首页 > 试题广场 >

阅读如下代码,请问两处console的输出结果[$##$][

[填空题]
阅读如下代码,请问两处console的输出结果12
 var Product = {
    
count: 1,
    
getCount: function( ) {
  
return this.count++;
     
}
 
};
 
console.log(Product.getCount( ));
 
var func = Product.getCount;
     
console.log(func( ));

var func = Product.getCount;执行后func是一个函数,然后执行func(),此时this指向的是window,window上并没有count,所以为输出为(undefined++)=>NaN
发表于 2022-04-09 16:53:07 回复(0)
    // undefined,NaN使用加号都是NaN
    console.log(undefined++);// NaN
    console.log(+undefined);// NaN 
    console.log(+null);// 0 
发表于 2020-02-19 23:44:23 回复(0)
undefined++ 等于NaN
发表于 2020-01-06 20:06:43 回复(0)
此时的this指向window,window.count++解析为undefined++,此时js会将undefined隐式转换为Number类型,所以结果为NaN
发表于 2019-07-02 23:34:43 回复(1)