Home | | Internet & World Wide Web HOW TO PROGRAM | | Internet Programming | | Web Programming | Boolean and Number Objects - JavaScript(Js)

Chapter: Internet & World Wide Web HOW TO PROGRAM - The Ajax Client - JavaScript: Objects

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail

Boolean and Number Objects - JavaScript(Js)

JavaScript provides the Boolean and Number objects as object wrappers for boolean true/ false values and numbers, respectively.

Boolean and Number Objects

 

JavaScript provides the Boolean and Number objects as object wrappers for boolean true/ false values and numbers, respectively. These wrappers define methods and properties useful in manipulating boolean values and numbers. Wrappers provide added functional-ity for working with simple data types.

 

When a JavaScript program requires a boolean value, JavaScript automatically creates a Boolean object to store the value. JavaScript programmers can create Boolean objects explicitly with the statement

 

var b = new Boolean( booleanValue  );

 

The constructor argument booleanValue specifies whether the value of the Boolean object should be true or false. If booleanValue is false, 0, null, Number.NaN or an empty string (""), or if no argument is supplied, the new Boolean object contains false. Otherwise, the new Boolean object contains true. Figure 11.10 summarizes the methods of the Bool-ean object.

 

JavaScript automatically creates Number objects to store numeric values in a Java-Script program. JavaScript programmers can create a Number object with the statement

 

var n = new Number( numericValue  );

 

The constructor argument numericValue is the number to store in the object. Although you can explicitly create Number objects, normally the JavaScript interpreter creates them as needed. Figure 11.11 summarizes the methods and properties of the Number object.





Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.