JavaScript Reference
Example:
//Sort numbers alphabetically and then numerically.
var arr = [700, 900, 6000, 80];
var numeric = function(x, y) {return x - y;};
arr.sort(); //arr is now [6000, 700, 80, 900]
arr.sort(numeric); //arr is now [80, 700, 900, 6000]
toString()
Syntax:
array .toString()
The method converts array to a string, which it re turns. The original array is not
changed.
The conversion is performed in two steps: First, every array element is converted to
a string. Second, all thus obtained strings are concatenated into a single string with
additional commas placed between them.
Example:
var arr = [1, 2, 3, 4];
var str = arr.toString(); //str is now "1,2,3,4".
str[3] //Returns ","
str[4] //Returns "3"
E.4 Boolean (Core JavaScript)
Boolean is one of the JavaScript fundamental data types. The Boolean object is a
wrapper around the prim itive boolean value. The essential role of this object is to
provide a toString() method, which converts boolean values true and false to
strings.
Object Instance Creation
Boolean() //Constructor
Syntax:
new Boolean(value ) //Constructor
Boolean(value ) //Type conversion function
When a boolean to string conversion is necessary, JavaScript often implicitly creates
a temporary Boole an o bject in ord er to be able to call its toString () method. Al-
though you will rarely need to create a Boolean object for yourself, you can do that
E.4. Boolean (Core JavaScript) 379
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.190.120