Many array functions are handy for handling strings. Although strings do not have these functions, strings can be handled by “borrowing” arrays in a non-changing way:

a.join; // undefined a.map; // undefined

var c = Array.prototype.join.call( a, “-” );

var d = Array.prototype.map.call( a, function(v){

return v.toUpperCase() + “.”; } ).join( “” );

c; // “f-o-o” d; // “F.O.O.” 

Var c = a // convert the value of a to a character array.split (“”) // reverse the characters in the array.reverse () // concatenate the characters in the array.join (“”);

c; // “oof” 


tofixed(..) 

Var a = 42.59;

a.toPrecision

1); // “4e+1” 2 ); / / “43” 3); / / “42.6” 4); / / “42.59” 5); / / “42.590”); / / “42.5900”


/ / error

return Math.abs( n1 – n2 ) < Number.EPSILON; 


ES6 Object.is

vara=2/”foo”; 

varb=-3*0;

Object.is( a, NaN ); 

Object.is( b, -0 );

Object.is( b, 0 );

// true // true

// false 

For versions prior to ES6, Object.is(..) There is a simple polyfill:

if (! Object.is) { Object.is = function(v1, v2) {

If (v1===0&&v2===0){

return1/v1===1/v2; }

// Check whether NaN if(v1! ==v1){

return v2 ! == v2; }

// Other circumstances

return v1 === v2; };

}


[[class]]

Object.prototype.toString.call( null );

// “[object Null]” 


~x === -(x+1)