Solo  当前访客:3 开始使用

js基础语法中的一些注意点


1、类型及类型转换

(1)false,true

0==false //true
0+false //0
0+true //1

(2)null,undefined

null == undefined//true

  (3)NaN

NaN == NaN //false

 

 2、作用域

js是函数作用域的,非块作用域

 

3、初始化顺序

1. 函数参数(若未传 ,初始化该参数值为undefined)
2. 函数声明(若发 命名冲突,会覆盖)
3. 变量声明(初始化变量值为undefined,若发 命名冲突,会忽略。

 
alert(x);   // function                
var x = 10; 
 alert(x);  // 10         
 x = 20; 
function x() {}  
alert(x);   // 20 
if (true) {   
   var a = 1;  
} else {   
   var b = true; 
 } 
alert(a);   // 1  
 alert(b);   // undefined

 

 

 

     


标题:js基础语法中的一些注意点
作者:hugh0524
地址:https://blog.uproject.cn/articles/2016/09/27/1474961184955.html

, , , , 0 0