A.2. Variables

Variables in ECMAScript are declared using the var keyword. Variable names must begin with a letter or an underscore followed by zero or more letters, numbers, and underscores. ECMAScript variables are case-sensitive.

ECMAScript supports weak typing. The programmer does not need to specify the type of a variable when declaring it; the interpreter automatically associates one of the five built-in ECMAScript types with the new variable based on the nature of the value assigned to it. These built-in types are shown in Table A-2.

Table A-2. ECMAScript built-in types
TypeDescriptionExamples
numbereither a floating-point or integer
var e = 2.71828;
var i = -1;

Booleanonly true or false
var b = true;

stringa string of characters
var s = "hello!";

functiona reference to ECMAScript code
var f = write;

objecta structured container of variables and/or functions
var o = 
  new Employee("Smith",     
      "John", 35, 
      writeEmployeeRecord);


Depending on where a variable is declared, it can be a global or local variable. A global variable is visible from within all functions. A local variable is visible only within the function in which it is declared.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.235.119