{"id":3145,"date":"2024-11-10T08:26:48","date_gmt":"2024-11-10T00:26:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3145\/"},"modified":"2024-11-10T08:26:48","modified_gmt":"2024-11-10T00:26:48","slug":"js%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e7%a9%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3145\/","title":{"rendered":"js\u5982\u4f55\u5224\u65ad\u7a7a"},"content":{"rendered":"<blockquote><p>\n  javascript \u4e2d\u5224\u65ad\u7a7a\u503c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1aundefined\uff1a\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u672a\u8d4b\u503c\u3002null\uff1a\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u8868\u793a\u663e\u5f0f\u7a7a\u503c\u3002\u96f6\u957f\u5ea6\u5b57\u7b26\u4e32\uff1a\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u4e3a\u7a7a\u5b57\u7b26\u4e32\u3002nan\uff1a\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u662f\u975e\u6570\u503c\u8868\u8fbe\u5f0f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110805064582750.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u5224\u65ad\u7a7a\u63d2\u56fe\" alt=\"js\u5982\u4f55\u5224\u65ad\u7a7a\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7528 JavaScript \u5224\u65ad\u7a7a\u503c\uff1f<\/strong><\/p>\n<p>\u5728 JavaScript \u4e2d\uff0c\u7a7a\u503c\u8868\u793a\u4e0d\u5b58\u5728\u7684\u503c\uff0c\u6216\u4e00\u4e2a\u53d8\u91cf\u672a\u8d4b\u503c\u3002\u5224\u65ad\u7a7a\u503c\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u9632\u6b62\u4ee3\u7801\u51fa\u73b0\u9519\u8bef\u6216\u610f\u5916\u884c\u4e3a\u3002<\/p>\n<p><strong>\u5224\u65ad\u7a7a\u503c\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u6765\u5224\u65ad\u53d8\u91cf\u662f\u5426\u4e3a\u7a7a\uff1a<\/p>\n<ul>\n<li> <strong>undefined\uff1a<\/strong> \u4f7f\u7528 undefined \u8fd0\u7b97\u7b26\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u672a\u8d4b\u503c\u3002<\/li>\n<\/ul>\n<pre>if (variable === undefined) {\n  \/\/ \u53d8\u91cf\u4e3a\u7a7a\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li> <strong>null\uff1a<\/strong> null \u662f\u4e00\u4e2a\u7279\u6b8a\u7684 JavaScript \u503c\uff0c\u7528\u4e8e\u8868\u793a\u663e\u5f0f\u7a7a\u503c\u3002<\/li>\n<\/ul>\n<pre>if (variable === null) {\n  \/\/ \u53d8\u91cf\u4e3a\u7a7a\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li> <strong>\u96f6\u957f\u5ea6\u5b57\u7b26\u4e32\uff1a<\/strong> \u7a7a\u5b57\u7b26\u4e32\u4e5f\u88ab\u89c6\u4e3a\u7a7a\u503c\u3002<\/li>\n<\/ul>\n<pre>if (variable === \"\") {\n  \/\/ \u53d8\u91cf\u4e3a\u7a7a\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li> <strong>NaN\uff1a<\/strong> NaN\uff08\u975e\u6570\u5b57\uff09\u4e5f\u662f JavaScript \u4e2d\u7684\u7279\u6b8a\u503c\uff0c\u8868\u793a\u975e\u6570\u503c\u8868\u8fbe\u5f0f\u3002<\/li>\n<\/ul>\n<pre>if (variable === NaN) {\n  \/\/ \u53d8\u91cf\u4e3a\u7a7a\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li> <strong>\u5e03\u5c14\u503c false\uff1a<\/strong> \u5e03\u5c14\u503c false \u8868\u793a\u5426\u5b9a\u503c\uff0c\u4f46\u5b83\u4e0d\u662f\u4e00\u4e2a\u7a7a\u503c\u3002<\/li>\n<\/ul>\n<pre>if (variable === false) {\n  \/\/ \u53d8\u91cf\u4e0d\u662f\u7a7a\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<pre>let variable1; \/\/ \u672a\u8d4b\u503c\nlet variable2 = null; \/\/ \u663e\u5f0f\u7a7a\u503c\nlet variable3 = \"\"; \/\/ \u7a7a\u5b57\u7b26\u4e32\nlet variable4 = NaN; \/\/ \u975e\u6570\u5b57\nlet variable5 = false; \/\/ \u5e03\u5c14\u503c false\n\nconsole.log(variable1 === undefined); \/\/ true\nconsole.log(variable2 === null); \/\/ true\nconsole.log(variable3 === \"\"); \/\/ true\nconsole.log(variable4 === NaN); \/\/ true\nconsole.log(variable5 === false); \/\/ false<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u5224\u65ad\u7a7a\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>javascript \u4e2d\u5224\u65ad\u7a7a\u503c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1aundefined\uff1a\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u672a\u8d4b\u503c\u3002null\uff1a\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u8868\u793a\u663e\u5f0f\u7a7a\u503c\u3002\u96f6\u957f\u5ea6\u5b57\u7b26\u4e32\uff1a\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u4e3a\u7a7a\u5b57\u7b26\u4e32\u3002nan\uff1a\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u662f\u975e\u6570\u503c\u8868\u8fbe\u5f0f\u3002 \u5982\u4f55\u7528 JavaScript \u5224\u65ad\u7a7a\u503c\uff1f \u5728 JavaScript \u4e2d\uff0c\u7a7a\u503c\u8868\u793a\u4e0d\u5b58\u5728\u7684\u503c\uff0c\u6216\u4e00\u4e2a\u53d8\u91cf\u672a\u8d4b\u503c\u3002\u5224\u65ad\u7a7a\u503c\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u9632\u6b62\u4ee3\u7801\u51fa\u73b0\u9519\u8bef\u6216\u610f\u5916\u884c\u4e3a\u3002 \u5224\u65ad\u7a7a\u503c\u7684\u65b9\u6cd5 \u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u6765\u5224\u65ad\u53d8\u91cf\u662f\u5426\u4e3a\u7a7a\uff1a undefined\uff1a \u4f7f\u7528 undefined \u8fd0\u7b97\u7b26\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u672a\u8d4b\u503c\u3002 if (variable === undefined) { \/\/ \u53d8\u91cf\u4e3a\u7a7a } \u767b\u5f55\u540e\u590d\u5236 null\uff1a null \u662f\u4e00\u4e2a\u7279\u6b8a\u7684 JavaScript \u503c\uff0c\u7528\u4e8e\u8868\u793a\u663e\u5f0f\u7a7a\u503c\u3002 if (variable === null) { \/\/ \u53d8\u91cf\u4e3a\u7a7a } \u767b\u5f55\u540e\u590d\u5236 \u96f6\u957f\u5ea6\u5b57\u7b26\u4e32\uff1a \u7a7a\u5b57\u7b26\u4e32\u4e5f\u88ab\u89c6\u4e3a\u7a7a\u503c\u3002 if (variable === &#8220;&#8221;) { \/\/ \u53d8\u91cf\u4e3a\u7a7a } \u767b\u5f55\u540e\u590d\u5236 NaN\uff1a NaN\uff08\u975e\u6570\u5b57\uff09\u4e5f\u662f JavaScript \u4e2d\u7684\u7279\u6b8a\u503c\uff0c\u8868\u793a\u975e\u6570\u503c\u8868\u8fbe\u5f0f\u3002 if (variable === [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3145","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3145"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3145\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}