
4
|
JavaScript Pocket Reference
that function. Global variables are visible throughout a Java-
Script program. Variables declared within a function are only
visible within that function. Unlike C, C++, and Java, Java-
Script does not have block-level scope: variables declared
within the curly braces of a compound statement are not
restricted to that block and are visible outside of it.
Data Types
JavaScript supports three primitive data types: numbers,
booleans, and strings; and two compound data types: objects
and arrays. In addition, it defines specialized types of objects
that represent functions, regular expressions, and dates.
Numbers
Numbers in JavaScript are represented in 64-bit floating-
point format. JavaScript makes no distinction between inte-
gers and floating-point numbers. Numeric literals appear in
JavaScript programs using the usual syntax: a sequence of
digits, with an optional decimal point and an optional expo-
nent. For example:
1
3.14
0001
6.02e23
Integers may also appear in hexadecimal notation. A hexa-
decimal literal begins with
0x:
0xFF // The number 255 in hexadecimal
When a numeric operation overflows, it returns a special
value that represents positive or negative infinity. When an
operation underflows, it returns zero. When an operation
such as taking the square root of a negative number yields an
error or meaningless result, it returns the special value
NaN,
which represents a value ...