标签:
本文是网易云课堂金旭亮老师的课程笔记,记录下来,以供备忘。
变量类型
只有6种 : 四种原始数据类型boolean , number, string , undefine, 其他object,function是对象
typeof,instanceof
直接看实例:
var obj = null; console.info(typeof obj); //Object var arr = []; console.info(arr instanceof Object); //true console.info(arr instanceof Array); //true
console.log(parseInt("34", 10)); //34 console.log(parseInt("34s5b", 10)); //34 console.log(parseInt("s", 10)); //NaN console.log(parseInt(3.14, 10)); //3
//number var value = 100; //string value = "qiu"; //object value = [1, ‘two‘, 3];
= 赋值 == 判等 === 严格判等 var x = 42; var y = "42"; console.log(x == y) //true; console.log(x === y) //false
var obj = null; if (obj === null) { alert("obj === null"); //此句将执行 } else { alert("obj!=null"); } alert(typeof obj); //object
undefine与null的 判等
var myVar; //true console.log(typeof myVar === "undefined"); console.log(myVar === undefined); var myVar2 = null; console.log(typeof myVar2); //object //true; console.log(myVar2 == null); console.log(myVar2 === null); //true console.info(myVar == myVar2); //undefine == null; 是true //false console.info(myVar === myVar2); //undefine === null; 是false
标签:
原文地址:http://www.cnblogs.com/xiaoguanqiu/p/4628597.html