渡一 this,笔试题
作者:互联网
1.//求 x,y,z的值 /* 考预编译 add只会用下面的,上面的被覆盖了 GO{ x:1, y:addFn, z:addFn, add:fn } */ var x=1,y=x=0; function add(n){ return n=n+1; } y=add(x); function add(n){ return n=n+3; } z=add(x); //output:x=1,y=4,z=4
//2作用域 A function foo(x){ console.log(arguments);//[1,2,3,4,5] return x } foo(1,2,3,4,5) B function foo(x){ console.log(arguments); return x }(1,2,3,4,5)//不能这样调用,但是不报错 C (function foo(x){ console.log(arguments); return x; })(1,2,3,4,5)//[1,2,3,4,5] D function foo(){ bar.apply(null,arguments)//bar(arguments) } function bar(x){ console.log(arguments) } foo(1,2,3,4,5) //[1,2,3,4,5]
parseInt(3,8) parseInt(3,2) parseInt(3,0) //output:3,NaN,NaN //进制 /* 10进制 1=1 10 = 10 100 = 10 ^ 3 1000 = 10 ^ 4 2进制 1 = 1 10 = 2 100 = 2 ^ 2 1000 = 2 ^ 3 10000 = 2 ^ 4 */
typeof可能返回的结果:string Number boolean undefined object function
typeof不可能返回的结果:NaN array
call & apply 传参列表不同
function b(x,y,a){ arguments[2] = 10; console.log(a);//10 } b(1,2,3); 如果改成下面,结果是什么 a=10; console.log(arguments[2]) //10
//逗号表达式,下面的会覆盖上面的fn,即f=fn g var f=( function f(){ return "1"; }, function g(){ return 2; } )(); typeof f;//namber
var x = 1; if(function f(){}){//这里()把里面的fn转成了表达式,引用就找不到了 x+=typeof f; x=x+"undefined" } console.log(x)//1undefined
undefined == null //true NaN != NaN //true function myisNaN(num){ var ret = Number(num); ret += ""; ret == "NaN" ? true : false; }
标签:function,渡一,console,log,10,笔试,arguments,return 来源: https://www.cnblogs.com/lisa2544/p/15302988.html