var x = .3 - .2; var y = .2 - .1; x == y; // false
var o = {x:1},p = {x:1}; o == p; // => false o === p; // => false var a = [], b = []; a == b; // => false a === b; // => false
值 | 转换为 | - | - | - |
---|---|---|---|---|
- | 字符串 | 数字 | 布尔值 | 对象 |
undefined | "undefined" | NaN | false | throws TypeError |
null | "null" | 0 | false | throws TypeError |
true | "true" | 1 | - | new Boolean(true) |
false | "false" | 0 | - | new Boolean(false) |
"" | - | 0 | false | new String("") |
"1.2" | - | 1.2 | true | new String("1.2") |
"sevens" | - | NanN | true | new String("sevens") |
0 | "0" | - | false | new Number(0) |
-0 | "0" | - | false | new Number(-0) |
NaN | "NaN" | - | false | new Number(NaN) |
1 | "1" | - | true | new Number(1) |
{} | 参考3.8.3节 | 参考3.8.3节 | true | |
[] | "" | 0 | true | |
[9] | "9" | 9 | true | |
['a'] | 使用join方法 | NaN | true | |
function(){} | 参考3.8.3节 | NaN | true |
null == undefined; // true "0" == 0; //比较前字符串转换成数字 true 0 == false; //布尔转换成数字 true "0" == false; //字符串和布尔值都转换成数字 true - 对日期对象进行转换 ````javascript var now = new Date(); typeof (now + 1); // => string , "+"将日期转换成了字符串 typeof (now - 1); // => Number: "-" 将对象转换成了数字
var scope = "global"; function f(){ console.log(scope); // undefined var scope = "local"; console.log(scope); // local }
因为局部变量在整个函数体始终都有定义的,就是说,在函数体内局部变量遮盖了同名全局变量。可是!只有在执行到var的时候才会被赋值。所以,上面的代码至关于:javascript
var scope = "global"; function f(){ var scope; console.log(scope); // undefined scope = "local"; console.log(scope); // local }
var o = {x:1,y:2,z:3}; var a = [],i = 0; for(a[i++] in o) ;
function inherit(p) { if (p == null) throw TypeError(); //若是Object.create()存在,则直接使用它 if (Object.create) return Object.create(p) //不然进一步检测 var t = typeof p; if (t !== "object" && t !== 'function') throw TypeError(); //定义一个空构造函数 function f() {}; //将其原型属性设置为p f.prototype = p; return new f(); }
Object.defineProperty(Object.prototype,"extend", { writable: true, enumerable: false, configurable: true, value: function (o){ //获得全部自有属性,包括不可枚举属性 var names = Object.getOwnPropertyNames(o); //遍历 for (var i = 0; i < names.length; i++){ if (names[i] in this) continue; var desc = Object.getOwnPropertyDescriptor(o,names[i]); Object.defineProperty(this,names[i],desc); } } } );
To be Continue.. java