{"id":115,"date":"2022-03-23T22:47:22","date_gmt":"2022-03-23T14:47:22","guid":{"rendered":"http:\/\/weboob.top\/blog\/?p=115"},"modified":"2022-03-23T22:47:22","modified_gmt":"2022-03-23T14:47:22","slug":"2-2-null-undefined-%e5%92%8c-boolean%e5%80%bc","status":"publish","type":"post","link":"http:\/\/blog.weboob.top\/?p=115","title":{"rendered":"2.2 null, undefined \u548c boolean\u503c"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/wangdoc.com\/javascript\/types\/general.html\">\u539f\u6587\u5730\u5740<\/a><br \/><a href=\"http:\/\/weboob.top\/blog\/?p=115\">\u6211\u7684\u535a\u5ba2<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"1null-%E5%92%8C-undefined\">1.null \u548c undefined<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"11-%E6%A6%82%E8%BF%B0\">1.1 \u6982\u8ff0<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><code>null<\/code>&nbsp;\u4e0e&nbsp;<code>undefined<\/code>&nbsp;\u542b\u4e49\u975e\u5e38\u76f8\u4f3c\uff0c\u5bf9\u4e8e\u53d8\u91cf\u6765\u8bf4\u57fa\u672c\u6ca1\u6709\u533a\u522b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var a = undefined;\n<em>\/\/ \u6216\u8005<\/em>\nvar a = null;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e&nbsp;<code>if<\/code>&nbsp;\u8bed\u53e5\u4e24\u8005\u90fd\u5c5e\u4e8e<code>\u5047\u503c<\/code>\u8303\u7574\uff0c\u76f8\u7b49\u8fd0\u7b97\u7b26\uff08<code>==<\/code>\uff09\u76f4\u63a5\u8f93\u51fa&nbsp;<code>true<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if(!undefined){\n    console.log('undefined is false');\n}\n<em>\/\/ undefined is false<\/em>\n\nif(!null){\n    console.log('null is false');\n}\n<em>\/\/ null is false<\/em>\n\nconsole.log(undefined == null)\n<em>\/\/ true<\/em>\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">1995 \u5e74&nbsp;<code>JavaScript<\/code>&nbsp;\u8bde\u751f\u7684\u65f6\u5019\u53ea\u6709<code>null<\/code>\uff0c\u6839\u636eC\u8bed\u8a00\u4f20\u7edf\uff0c<code>null<\/code>&nbsp;\u53ef\u4ee5\u81ea\u52a8\u8f6c\u4e3a&nbsp;<code>0<\/code>&nbsp;\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log(Number(null)) <em>\/\/ 0<\/em>\nconsole.log(5 + null) <em>\/\/ 5<\/em>\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">JavaScript\u7684\u8bbe\u8ba1\u8005 Brendan Eich \u89c9\u5f97\u4e0d\u884c\u3002\u4ed6\u8ba4\u4e3a\u8868\u793a\u201c\u65e0\u201d\u7684\u503c\uff0c\u6700\u597d\u4e0d\u662f\u5bf9\u8c61\u3002\u4e14\u521a\u5f00\u59cbJS\u4e0d\u5305\u62ec\u9519\u8bef\u5904\u7406\u673a\u5236\uff0c\u81ea\u52a8\u8f6c\u53d8\u4e3a0\uff0c\u4e0d\u5bb9\u6613\u53d1\u73b0\u9519\u8bef\u3002\u56e0\u6b64\u8bbe\u8ba1\u4e86<code>undefined<\/code>\u8868\u793a\u201c\u6b64\u5904\u65e0\u5b9a\u4e49\u201d\u7684\u539f\u59cb\u503c\uff0c\u8f6c\u53d8\u4e3a\u6570\u503c\u662f<code>NaN<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log(Number(undefined)) <em>\/\/ NaN<\/em>\nconsole.log(5 + undefined) <em>\/\/ NaN<\/em>\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"12%E7%94%A8%E6%B3%95%E5%92%8C%E5%90%AB%E4%B9%89\">1.2\u7528\u6cd5\u548c\u542b\u4e49<\/h5>\n\n\n\n<ul class=\"wp-block-list\"><li>null\uff1a\u7a7a\u7f6e\u3001\u672a\u51fa\u9519<\/li><li>undefined\uff1a\u672a\u5b9a\u4e49\u3002\u591a\u6570\u662f\u9884\u671f\u4e4b\u5916\u7684\u9519\u8bef<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f\u51e0\u79cd\u8fd4\u56de<code>undefined<\/code>\u7684\u573a\u666f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/\/ \u58f0\u660e\u53d8\u91cf\uff0c\u4f46\u662f\u6ca1\u6709\u8d4b\u503c\u65f6\u5f15\u7528\u6b64\u53d8\u91cf<\/em>\nvar i;\nconsole.log(i); <em>\/\/undefined<\/em>\n\n<em>\/\/ \u8c03\u7528\u51fd\u6570\u65f6\uff0c\u672a\u4f20\u5165\u53c2\u6570<\/em>\nfunction(x){\n    console.log(x);\n}\nf() <em>\/\/ undefined<\/em>\n\n<em>\/\/ \u5bf9\u8c61\u6ca1\u6709\u8d4b\u503c\u7684\u5c5e\u6027<\/em>\nvar o = new Object();\nconsole.log(o.p);   <em>\/\/ undefined<\/em>\n\n<em>\/\/ \u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u503c<\/em>\nfunction(){}\nconsole.log(f()) <em>\/\/ undefined<\/em>\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"2%E5%B8%83%E5%B0%94%E5%80%BC\">2.\u5e03\u5c14\u503c<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>true<\/li><li>false<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u7684\u8fd0\u7b97\u7b26\u4f1a\u8fd4\u56de\u5e03\u5c14\u503c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u524d\u7f6e\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a<code>!<\/code><\/li><li>\u76f8\u7b49\u8fd0\u7b97\u7b26\uff1a<code>===<\/code>&nbsp;<code>!==<\/code>&nbsp;<code>==<\/code>&nbsp;<code>!=<\/code><\/li><li>\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff1a<code>&gt;<\/code>&nbsp;<code>&gt;=<\/code>&nbsp;<code>&lt;<\/code>&nbsp;<code>&lt;=<\/code><\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u5982\u679cJavaScript\u9884\u671f\u67d0\u4e2a\u4f4d\u7f6e\u5e94\u8be5\u662f<code>boolean<\/code>\u7c7b\u578b\uff0c\u81ea\u52a8\u5c06\u8be5\u4f4d\u7f6e\u7684\u503c\u8f6c\u6362\u4e3a&nbsp;<code>boolean<\/code>&nbsp;\u7c7b\u578b\u3002\u4ee5\u4e0b\u5185\u5bb9\u8f6c\u6362\u540e\u662f&nbsp;<code>false<\/code>&nbsp;\uff0c\u5176\u4f59\u90fd\u89c6\u4e3a&nbsp;<code>true<\/code><\/p><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>undefined<\/li><li>null<\/li><li>false<\/li><li>0<\/li><li>NaN<\/li><li>&#8220;&#8221; \u6216 &#8221; (\u7a7a\u5b57\u7b26\u4e32)<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a7a\u7684\u6570\u7ec4&nbsp;<code>[]<\/code>&nbsp;\u548c\u7a7a\u7684\u5bf9\u8c61&nbsp;<code>{}<\/code>&nbsp;\u5bf9\u5e94\u7684\u5e03\u5c14\u503c\u90fd\u662f&nbsp;<code>true<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if(&#91;]){\n    console.log('true');\n}\n<em>\/\/ true<\/em>\n\nif({}){\n    console.log('true');\n}\n<em>\/\/ true<\/em>\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"3%E5%8F%82%E8%80%83%E9%93%BE%E6%8E%A5\">3.\u53c2\u8003\u94fe\u63a5<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Axel Rauschmayer,&nbsp;<a href=\"http:\/\/www.2ality.com\/2013\/01\/categorizing-values.html\">Categorizing values in JavaScript<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740\u6211\u7684\u535a\u5ba2 1.null \u548c undefined 1.1 \u6982\u8ff0 null&nbsp;\u4e0e&nbsp;und [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,10,5],"tags":[],"class_list":["post-115","post","type-post","status-publish","format-standard","hentry","category-es5","category-js","category-code_article"],"_links":{"self":[{"href":"http:\/\/blog.weboob.top\/index.php?rest_route=\/wp\/v2\/posts\/115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.weboob.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.weboob.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.weboob.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.weboob.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=115"}],"version-history":[{"count":0,"href":"http:\/\/blog.weboob.top\/index.php?rest_route=\/wp\/v2\/posts\/115\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.weboob.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.weboob.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.weboob.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}