@nemos
        
        2017-05-06T03:46:52.000000Z
        字数 1057
        阅读 750
    web
变量提升: 所有变量声明都会提到所在作用域的最前处
标签语法
top:for (var i = 0; i < 3; i++){for (var j = 0; j < 3; j++){if (i === 1 && j === 1) break top;console.log('i=' + i + ', j=' + j);}}
typeof关键字
typeof x // 判断内置对象类型// 仅支持 num,str,bool,func,undef,其他均为objtypeof v === "undefined" // 判断变量是否被定义
返回undefined的情况
// 变量声明了,但没有赋值var i;i // undefined// 调用函数时,应该提供的参数没有提供,该参数等于undefinedfunction f(x) {return x;}f() // undefined// 对象没有赋值的属性var o = new Object();o.p // undefined// 函数没有返回值时,默认返回undefinedfunction f() {}f() // undefined
假值 
* undefined 
* null 
* false 
* 0 
* NaN 
* ""或''(空字符串) 
number类型 
js内部所有数字都以64位浮点存储
parseInt(obj, base) // 转化数字parseFloat() // 同上Number() // 转化数字,不能转化返回NaNString() // 转化字符btoa(string) // base64编码atob('SGVsbG8gV29ybGQh') // "Hello World!"
js 对象和字典差不多是一个东西 
数组为以数组为键名的特殊对象
f.name // 返回参数括号前的函数名f.length // 返回参数个数f.toString() // 返回函数源码,内部注释也会返回arguments // 函数参数的类数组对象,不定参时使用arguments.callee // 返回对应函数
错误处理
function throwit() {throw new Error('');}function catchit() {try {throwit();} catch(e) {console.log(e.stack); // print stack trace} finally {console.log()}}catchit()// Error// at throwit (~/examples/throwcatch.js:9:11)// at catchit (~/examples/throwcatch.js:3:9)// at repl:1:5