前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >javascript当中null和?developer/article/1517341/undefined的==和===的比较

javascript当中null和?developer/article/1517341/undefined的==和===的比较

作者头像
马克java社区
修改2019-10-08 12:12:48
5780
修改2019-10-08 12:12:48
举报
文章被收录于专栏:java大数据java大数据

例 3.1.3(null和?developer/article/1517341/undefined的==和===的比较) <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <script> //马克-to-win:声明变量x /* if a value is not set, its typeof is ?developer/article/1517341/undefined, its value is ?developer/article/1517341/undefined, if a value= null, its typeof is object, its value is null,but when you use == to test, they are the same, but when to use === to test, they are not the same,== means as long as value is the same, ok, but === means type also must be equal. */ var x; var z1 = "d"; var y = null; // document.writeln("z1 is"+z1); /*if you cancel commenting out the following statement, it will give the blank page, which means it has error.*/ // document.writeln(zyx); document.writeln(x + " is x"); document.writeln(typeof(x) + " is typeof(x)"); document.writeln(y + " is y"); document.writeln(typeof(y) + " is typeof(y)"); var z = ?developer/article/1517341/undefined; document.writeln(z + " is z"); document.writeln(typeof(z) + " is typeof(z)"); if (y == ?developer/article/1517341/undefined) { document.writeln('null and ?developer/article/1517341/undefined is interchangable'); } if (z1 != null) { document.writeln('z1 != null'); } if (y === ?developer/article/1517341/undefined) { document.writeln('null and ?developer/article/1517341/undefined is exactly the same'); } if (x == ?developer/article/1517341/undefined) { document.writeln('声明变量后默认值为?developer/article/1517341/undefined'); } if (x === ?developer/article/1517341/undefined) { document.writeln('声明变量后默认值为exactly the same as ?developer/article/1517341/undefined'); } if (x == null) { document.writeln('声明变量后默认值为null'); }

更多请见:https://blog.csdn.net/qq_44594249/article/details/99689140

本文系转载,前往查看

如有侵权,请联系?cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系?cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com