HTML and CSS Reference
In-Depth Information
Data Types
Data type refers to the category of data held by a variable. JavaScript variables are
dynamically typed, which means they do not have to be declared as a specific type before
using them in Web page. JavaScript supports several data types, including primitive data
types (numbers, strings, and boolean values), compound types (objects and arrays), special
types (null and undefined), regular expressions, and functions. Table G-3 summarizes the
primitive and special data types.
Table G-3 Primitive and Special Data Types
Data Type
Form
Description
Example
Range
Boolean
True/False
Can represent yes or no,
on or off, true or false
check_pt 5 true
true or false
test_2 5 false
Null
No value
Empty
null
val_hold 5 null
Numeric
Integer
Positive or negative
numbers with no
decimal places
count 5 4
-2 32 to 2 32
Floating-point
Positive or negative
numbers, with
decimal places, or
numbers written using
exponential notation
accum 5 4.678
Approximately
1 1.79769e308 to -1.7e308
amt 5 −67.126
distance 5 2e11
Special numbers
NaN
ValType 5 NaN
NaN means Not a Number
Infinity (or MAX_VALUE
or POSITIVE_INFINITY)
highNum 5
-Infinity
MAX_VALUE:
1 1.7976931348623157e308
-Infinity (or MIN_VALUE
or NEGATIVE_INFINITY)
highNegNum 5
-Infinity
MIN_VALUE: 1 5e-324
String
Text and
nonnumeric
characters
A set of continuous
characters surrounded
by quotation marks
zero or more characters
productName 5
“Router”
phone =
"555-1212"
Undeined
No value
A variable that has
been declared but not
yet assigned a value
var i
undefined
Variable Names
A variable name (also called an identifier) ) must begin with a letter, dollar sign ($), or
underscore (_) and cannot be a reserved word shown in Table G-1 on the previous page.
Variable names are case sensitive and may not contain a space. Variables can be declared
with the var statement, where they can also be initialized.
Although the dollar sign ($) is a valid variable name character, most developers avoid
using it because the dollar sign can also indicate machine-generated code to the interpreter.
In addition, the number of characters in a variable is not subject to any specific limitation.
Older browsers, however, do have a limitation of 255 characters for an entire statement.
A variable name cannot use a period because periods separate objects, properties,
and methods. See Table G-4 on the next page for examples of valid and invalid variable
names. In addition, you must remember that, in JavaScript, variable names are case
sensitive. If you create a form and use mixed-case spelling, such as State, as a variable
name, and later use the uppercase spelling, STATE, as a variable name, JavaScript will
treat these spellings as two different variable names.
Search WWH ::




Custom Search