IT. Expert System.

Java Script

Variables


Variables

Variables are used for storing values or expressions.

Naming Rules

The following rules apply when naming variables in JavaScript:

Rule 1: Variable names are case sensitive

Rule 2: Variable names must begin with a letter or the underscore character ( _ ).

Creating Variables

Creating variables in JavaScript is often referred to as "declaring" variables. JavaScript variables are declared using the var keyword:

var myVariable;

Once a variable has been declared, it can be assigned a value:

myVariable = 10;

In addition, variables can be declared and assigned a value at the same time:

var myVariable = 10;

Note: Variables declared outside any function, and variables first used within functions without being declared using var, have a "global" scope.

Data Types

JavaScript has very few built-in data types. They are: Number, String, Boolean, and Array. In addition, there is Null and Undefined which are special data types.

Number

Numbers are the most basic data type. JavaScript does not make a distinction between integer values and floating-point values. All numbers in JavaScript are represented as floating-point values.

JavaScript also supports exponential notation. To denote the exponent, use a letter e right after the base number and before the exponent.

Base-8 numbers start with a
zero and only use zero through seven.

Base-16 numbers start with 0x or
0X and use zero through nine and A through F.

num1 = 123;
num2 = 0.45;
num3 = 123.45;
num4 = 1.23e4; // Exp. Notation
num5 = 0123; // Base-8
num6 = 0xFFF; // Base-16

String

A String is a sequence of Unicode letters, digits, punctuation, symbols, etc and is the data type for representing text. Literal strings are specified in JavaScript by enclosing the text in matching pairs of single or double quotation marks.

str1 = "A string of text";
str2 = 'A string of text';
str3 = "Text\twith\ttabs";
str4 = "John said, \"Hello\"";

Note: In JavaScript, to represent a single character, use a string that has a length of 1.

Boolean

A Boolean is a variable with a value of true or false. JavaScript also allows the use of the number 1 for true and the number 0 for false.

bool1 = true;
bool2 = 1; // also true
bool3 = false;
bool4 = 0; // also false

Because true and false are reserved words, they are recognized by JavaScript as Boolean values.

Array

An array is a collection of data values. Each data value in an array has a number, or index. Values are retrieved from an array by enclosing an index in square brackets after the array name. Array indexes begin with zero, therefore, the first element in an array would be:

var first = myArray[0];

Arrays may contain any type of JavaScript data, including references to other arrays or to objects or functions.

null

The null keyword is used to indicate that a variable has no value.

novalue1 = null;

undefined

The undefined property indicates that a variable has not been assigned a value.

JavaScript treats undefined as being equal to null, but they are not the same values.

var novalue1;
document.write(typeof novalue1);

This produces the following result:


When the undefined value is used in a Boolean context, it converts to false. When used in a numeric context, it converts to NaN. And when used in a string context, it converts to "undefined".



Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 558 / 158776861. Delta: 0.00349 с