declaration is "hoisted" function foo() { a = 3; console.log( a ); // 3 var a; // declaration is "hoisted" // to the top of `foo()` } console.log( a ); // 2
// explicitly coerced here a; // "42" b; // 42 -- the number! var a = "42"; var b = a * 1; // "42" implicitly coerced to 42 here a; // "42" b; // 42 -- the number!
var a = new String( "abc" ); // Manually boxing var b = new Number( 42 ); var c = new Boolean( true ); a.valueOf(); // "abc" b.valueOf(); // 42 c.valueOf(); // true b = a + ""; // ‘b’ has the unboxed primitive value "abc" typeof a; // "object" typeof b; // "string"