iccat 发表于 2013-2-7 15:18:36

javascript中“==”和“===”区别

最近看书突然发现有在js中有===用法,上网查资料发现三个等是精确比较的意思,不仅值相同,还要类型相同。不说废话,直接上代码。
<html> <head><title> ===和==区别 </title></head> <body><script type="text/javascript">var y = 5; if(y == "5"){ document.write("== '5' true"); }else{ document.write("== '5' false "); } document.write("</br>");if(y == 5){ document.write("== 5 数字 is true "); } else{ document.write("== 5数字 false "); } document.write("</br>");if( y === 5){ document.write("=== 数字5 is true "); } else{ document.write("=== 数字5 false "); } document.write("</br>");if(y !== "5"){ document.write("!== '5' is true "); } else{ document.write("!== '5' is false"); } </script></body></html>
页: [1]
查看完整版本: javascript中“==”和“===”区别