变量
-
JS 中使用 typeof 能得到哪些类型
typeof undefined //undefined typeof 'abc' //string typeof 123 //number typeof true //boolean //以上四点可以看出,typeof只能区分值类型的详细类型 typeof {} //object typeof [] //object typeof null //object typeof console.log //function
-
何时使用 === 和 ==
if (obj.a == null) { //这里相当于obj.a === null || obj.a === undefined的简写形式 // 这是jqurey源码中推荐的写法 }
-
JS 中有哪些内置函数
Object Array Boolean Number String Function Date RegExp Error
-
JS 变量按照储存方式区分为哪些类型,并描述其特点
-
变量类型
- 值类型
var a = 100 var b = a a = 200 console.log(b) //100
- 引用类型
var a = { age: 20 } var b = a b.age = 21 console.log(a.age) //21
-
-
如何理解 JSON
//JSON只不过是一个JS对象 JSON.stringify({ a: 10, b: 20 }) JSON.parse('{"a":10,"b":20}')
变量计算 - 强制类型转换
-
字符串拼接
var a = 100 + 10 //110 var b = 100 + '10' //'10010'
-
==运算符
100 == '100' //true 0 == '' //true null == undefined //true
-
if 语句
var a = true if (a) { //... } var b = 100 if (b) { //... } var c = '' if (c) { //... }
-
逻辑运算符
console.log(10 && 0) //0 console.log('' || 'abc') //'abc' console.log(!window.abc) //true //判断一个变量会被当做true还是false var a = 100 console.log(!!a) //true