
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
66
|
Chapter 3: Data and Datatypes
true // Special keyword true identifies this as a Boolean
null // Special keyword null identifies this as the null type
undefined // Special keyword undefined identifies the undefined type
["hello", 2, true] // Square brackets and values separated by commas
// indicate that this is an array
{x: 234, y: 456} // Curly braces and property name/value pairs separated
// by commas indicate that this is an object
As you can see, using correct syntax with data literals is extremely important. Incor-
rect syntax may cause an error or result in the misinterpretation of a datum’s con-
tent. For example:
animal // Missing quotes--animal is interpreted as a variable,
// not a string of text
"1.35" // Numbers in quotes are treated as strings, not numbers
1. 35 // Space before the 3 causes an error
"animal // Missing closing quotation mark causes an error
Automatic Complex Expression Typing
The interpreter computes an expression’s value in order to determine its datatype.
Consider this example:
pointerX = _xmouse;
Because _xmouse stores the location of the mouse pointer as a number, the type of the
expression
_xmouse will always be a number; so, the variable pointerX also becomes a
number.
Usually, the datatype that is automatically determined by the interpreter matches ...