• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

1.4. Data Types

JavaScript supports three primitive data types: numbers, boolean values, and strings. In addition, it supports two compound data types: object and arrays. Functions are also a first class data type in JavaScript, and JavaScript 1.2 adds support for regular expressions (described later) as a specialized type of object.


Numbers in JavaScript are represented in 64-bit floating-point format. JavaScript makes no distinction between integers 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 exponent. For example:


Integers may also appear in octal or hexadecimal notation. An octal literal begins with 0, and a hexadecimal literal begins with 0x:

0377 // The number 255 in octal
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 that is not-a-number. Use the global function isNaN() to test for this value.

The Number object defines useful numeric constants. The Math object defines various mathematical operations.


The boolean type has two possible values, represented by the JavaScript keywords true and false. These values represent truth or falsehood, on or off, yes or no, or anything else that can be represented with one bit of information.


A JavaScript string is a sequence of arbitrary letters, digits, and other characters. The ECMA-262 standard requires JavaScript to support the full 16-bit Unicode character set. IE 4 supports Unicode, but Navigator 4 supports only the Latin-1 character set.

String literals appear in JavaScript programs between single or double quotes. One style of quotes may be nested within the other:

"Wouldn't you prefer O'Reilly's book?"

When the backslash character (\) appears within a string literal, it changes or "escapes" the meaning of the character that follows it. The following table lists these special escape sequences:



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint