双等号==判断值是否相等
三等号===先判断类型是否相同,再判断值是否相等
undefined==null结果为什么?
undefined===null结果为什么?
思考:如何判断变量是否可用?
答:先判断类型是否为undefined,再判断值是否为null,否则可用
提示: typeof(n)!='undefined‘
非数字判断:isNaN()
eval()用于将一段字符串转换成js代码执行
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
//var p = '123';
//var m = 123;
//alert(p == m); //true
//var m;
//var n = null;
//alert(m == n);//true
//var m;
//var n = null;
//alert(m === n);//false
//var temp = null;
//alert(typeof (temp));//chrome:object,不同浏览器返回不同
var temp;
if (typeof (temp) == 'Undefined' || temp === null) {//和if(temp==null)相同
alert('不可用');
}
//eval('alert("hhh")');
//var p = 123;
//alert(isNaN(p));
</script>
</body>
</html>