這些都是關於函數作用域和預解析的一些題目 /*function foo1() { return { bar:"hello", he :"hehe" }; } alert(foo1());*/ 關於return的坑 /*function foo1() { return { bar:"hello" } ...
這些都是關於函數作用域和預解析的一些題目 /*function foo1() { return { bar:"hello", he :"hehe"
}; } alert(foo1());*/ 關於return的坑 /*function foo1() { return { bar:"hello" } } alert(foo1());*/ -------------------------------- /* (function(){ var a = b = 3; })(); //console.log(a); console.log(b); console.log("a defined? " + (typeof a !== 'undefined')); console.log("b defined? " + (typeof b !== 'undefined')); */ ------------------------------- /* var a = 10; function test(){ a = 100; alert(a); alert(window.a); var a; alert(a); return a ; }
test(); alert(a); */ ------------------------------ /* function test(){ console.log(a); console.log(foo()); var a=1; function foo(){ return 2; } } test();*/ ------------------------------ /* var a = 10; sayHi(); function sayHi() { a = a + 10; alert(a); return a; } alert(a); alert(sayHi()+10); */ 很好的案例 /* var a = 10; sayHi(); function sayHi() { var a = a + 10; alert(a); return a; } alert(a); alert(sayHi()+10) */ ----------------------------- /*var s = 'abc12345'; var num =parseInt(s); if(num ==NaN){ alert('NaN'); }else if(typeof num == 'number'){ alert('number'); }else if(num =='abc'){ alert('abc'); }else { alert ('str'); }*/