, JS , . , , null .
new String() , , - :
- equals
- typeof yields 'object' 'string'
, ,
var a = new String('hello'), b = new String('hello');
var strA = String('hello'), strB = String('hello');
var literalA = 'hello', literalB = 'hello';
console.log( a == b );
console.log(typeof a);
console.log( strA == strB);
conole.log( literalA == literalB);
console.log( typeof strA);
console.log( typeof literalA );
console.log( strA == literalA)
, , , valueOf() .
console.log(a.valueOf() == b.valueOf()); // outputs true;
, , .
console.log(a.constructor == String);
Just be careful if you work with frames, pop-ups, iframes, for each window object there is a different String constructor, i.e.
// outputs false
console.log( window.frames.frameA.String == window.frames.frameB.String)
source
share