标签:使用 类型 强制 情况 识别 body 连接 else 对象
取值范围:正无穷 - 负无穷、NaN 正无穷:Number.POSITIVE_INFINITY 负无穷:Number.NEGATIVE_INFINITY
1 var v = NaN; 2 alert(typeof v);//number
1 var v = ""; 2 alert(typeof v);//string
1 var v = true; 2 alert(typeof v);//boolean
var v; alert(typeof v);//undefined
1 var v = function(){ }; 2 alert(typeof v);//function
1 var v = []; 2 alert(typeof v);//object
1 console.log(parseInt("12.724.12.234")); //12 2 console.log(parseInt("1a12s"));//1 3 console.log(parseInt(".123"));//NaN 4 console.log(parseInt("s12345"));//NaN 5 console.log(parseInt(true));//NaN 6 console.log(parseInt(""));//NaN 7 console.log(parseInt(" +00123"));//123
1 console.log(parseFloat("12.724.12.234")); //12.724 2 console.log(parseFloat("1a12s"));//1 3 console.log(parseFloat(".123"));//0.123 4 console.log(parseFloat("s12345"));//NaN 5 console.log(parseFloat(true));//NaN 6 console.log(parseFloat(""));//NaN
1 var v = []; 2 console.log(Number(v));//0 3 var v = [‘‘]; 4 console.log(Number(v)); //0 5 var v = [‘ ‘]; 6 console.log(Number(v)); //0 7 var v = [‘ +00112‘]; 8 console.log(Number(v)); //112
1 var a = 12323; 2 console.log(String(a));//12323 3 var a = true; 4 console.log(String(a));//true 5 var a = function(){}; 6 console.log(String(a));//function(){}
1 var a = []; 2 console.log(Boolean(a));//true
1 var a = 1; 2 var b = 3; 3 console.log(a!=b && a > b);//false
1 console.log(a!=b || a > b);//true
1 console.log(!(a != b));//false
1 var a = 0; 2 var b = 1; 3 var c = a > b?a:b; 4 console.log(c);//1
1 //利用逻辑运算符简化运算 2 var a = 1; 3 var b = 1; 4 function fn(){ 5 alert("条件成立"); 6 } 7 function fn2(){ 8 alert("条件不成立"); 9 } 10 11 /*if(a != b){ 12 fn(); 13 } else { 14 fn2(); 15 }*/ 16 17 //&&并且:(当第一个条件成立时,才会去执行第二条件) 当左侧成立时就会只执行右侧代码,否则直接返回 false 18 //第一个条件为false,不会执行fn 19 a!=b&&fn(); 20 21 //当第一个条件成立时,返回true,语句结束,条件不成立就会去 执行右侧 22 //第一个条件为false,会执行fn2 23 a!=b||fn2();
1 var a = function(){}; 2 var b = 1; 3 alert(a + b);//function(){}1
1 var a = function(){}; 2 var b = 1; 3 alert(a - b);//NaN
1 var a = true; 2 var b = 1; 3 alert(a == b);//true
1 alert(!"");//true
1 var a = "100px"; 2 var b = "100px"; 3 alert(Number(a));//NaN 4 alert(Number(b));//NaN 5 alert(Number(a)==Number(b));//false
1 var a = true; 2 alert(isNaN(a));//false
1 function isReallyNaN(x) { 2 return x !== x; 3 }
标签:使用 类型 强制 情况 识别 body 连接 else 对象
原文地址:http://www.cnblogs.com/wy715/p/7604462.html