首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript中“==”跟“===”区别

2012-09-21 
javascript中“”和“”区别最近看书突然发现有在js中有用法,上网查资料发现三个等是精确比较的意思,

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>

热点排行