首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    javascript当中null和undefined的==和===的比较

    例 3.1.3(null和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 undefined, its value is 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 = undefined; document.writeln(z + " is z"); document.writeln(typeof(z) + " is typeof(z)"); if (y == undefined) { document.writeln('null and undefined is interchangable'); } if (z1 != null) { document.writeln('z1 != null'); } if (y === undefined) { document.writeln('null and undefined is exactly the same'); } if (x == undefined) { document.writeln('声明变量后默认值为undefined'); } if (x === undefined) { document.writeln('声明变量后默认值为exactly the same as undefined'); } if (x == null) { document.writeln('声明变量后默认值为null'); }

    00
    领券