日期:2014-05-16 浏览次数:20472 次
var myVar = 5; if(myVar == '5'){ //返回true,因为JavaScript是弱类型 alert("hi"); //这个alert将执行,因为JavaScript通常不在意数据类型 } switch(myVar){ case '5': alert("hi"); //这个alert将不会执行,因为数据类型不匹配 }
<div>123123123123123</div> <div>123123123123123</div> <div>123123123123123</div> <div>123123123123123</div> <script> window.onload = function(){ document.write(""); } </script>
for(var n in obj){ if(obj.hasOwnProperty(n)){ ... } }
if(flag){ param = ( a == undefined ) ? 1 : 2; }
var undefined; if(flag){ param = ( a == undefined ) ? 1 : 2; }
function a(x){ x && a(--x); }; var a; alert(a);//function a(x){...}
function a(x){ x && a(--x); }; var a = 1; alert(a);//1
var key = {name:"cc"}; var key2 = {}; var arr = []; arr[key] = "haha"; arr[key2] = "hehe"; alert(arr[key]);//hehe alert(arr[{}]);//hehe这里会有一个隐式转换,会调用对象的toString方法
var args = [].slice.call(arguments,0)
var obj = {}; [].push.apply(obj,[1,2,4]);//{0:1,1:2,2:4,length:3}