Section 2.6. Literals


2.6. Literals

A literal is a data value that appears directly in a program. The following are all literals:

 12               // The number twelve 1.2              // The number one point two "hello world"    // A string of text 'Hi'             // Another string true             // A Boolean value false            // The other Boolean value /javascript/gi   // A "regular expression" literal (for pattern matching) null             // Absence of an object 

In ECMAScript v3, expressions that serve as array and object literals are also supported. For example:

 { x:1, y:2 }    // An object initializer [1,2,3,4,5]     // An array initializer 

Literals are an important part of any programming language, because it is impossible to write a program without them. The various JavaScript literals are described in detail in Chapter 3.




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net