{"id":516,"date":"2025-12-05T19:28:57","date_gmt":"2025-12-05T11:28:57","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=516"},"modified":"2025-12-05T19:28:57","modified_gmt":"2025-12-05T11:28:57","slug":"javascript%e5%8f%8c%e9%87%8d%e5%90%a6%e5%ae%9a%e8%bf%90%e7%ae%97%e7%9a%84%e5%85%b7%e4%bd%93%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/05\/javascript%e5%8f%8c%e9%87%8d%e5%90%a6%e5%ae%9a%e8%bf%90%e7%ae%97%e7%9a%84%e5%85%b7%e4%bd%93%e4%bd%bf%e7%94%a8\/","title":{"rendered":"Javascript\u53cc\u91cd\u5426\u5b9a\u8fd0\u7b97\u7684\u5177\u4f53\u4f7f\u7528"},"content":{"rendered":"\n<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u7bc7 <strong>\u8d85\u6e05\u6670\u3001\u5e26\u793a\u4f8b\u3001\u9002\u5408\u65b0\u624b\u548c\u8fdb\u9636\u5f00\u53d1\u8005<\/strong> \u7684<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u300aJavaScript \u53cc\u91cd\u5426\u5b9a (!!) \u8fd0\u7b97\u7684\u5177\u4f53\u4f7f\u7528\u8be6\u89e3\u300b<\/h1>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2705 \u4e00\u3001\u4ec0\u4e48\u662f\u53cc\u91cd\u5426\u5b9a <code>!!<\/code><\/h1>\n\n\n\n<p>\u5728 JavaScript \u4e2d\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>!<\/code> \u662f\u903b\u8f91\u975e\uff1a\u5c06\u503c\u8f6c\u4e3a <strong>\u5e03\u5c14\u503c<\/strong> \u518d\u53d6\u53cd<\/li>\n\n\n\n<li><code>!!<\/code> \u5c31\u662f\uff1a<strong>\u5c06\u4efb\u610f\u503c\u5feb\u901f\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c\uff08Boolean\uff09<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n!!value\n\n<\/pre><\/div>\n\n\n<p>\u7b49\u540c\u4e8e\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nBoolean(value)\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2705 \u4e8c\u3001\u4e3a\u4ec0\u4e48\u8981\u7528 <code>!!<\/code>\uff1f<\/h1>\n\n\n\n<p>\u56e0\u4e3a JavaScript \u4e2d\u5f88\u591a\u503c\u88ab\u8ba4\u4e3a\u662f \u201c\u771f\u503c (truthy)\u201d \u6216 \u201c\u5047\u503c (falsy)\u201d\uff0c<br><code>!!<\/code> \u53ef\u4ee5\u5feb\u901f\u5224\u65ad\u4e00\u4e2a\u53d8\u91cf <strong>\u662f\u5426\u6709\u6709\u6548\u503c<\/strong>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2705 \u4e09\u3001\u54ea\u4e9b\u503c\u662f false\uff1f<\/h1>\n\n\n\n<p>\u4ee5\u4e0b 8 \u4e2a\u503c\u4f1a\u88ab\u8f6c\u6362\u6210 <code>false<\/code>\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfalse\n0\n-0\n0n  \/\/ BigInt zero\n&quot;&quot;  \/\/ \u7a7a\u5b57\u7b26\u4e32\nnull\nundefined\nNaN\n\n<\/pre><\/div>\n\n\n<p>\u5176\u4ed6\u6240\u6709\u503c\u90fd\u4e3a <code>true<\/code>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2705 \u56db\u3001\u5e38\u7528\u793a\u4f8b\uff08\u6838\u5fc3\u573a\u666f\uff09<\/h1>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2b50 \u573a\u666f 1\uff1a\u5feb\u901f\u5224\u65ad\u53d8\u91cf\u662f\u5426\u5b58\u5728<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst name = &quot;\u963f\u6770&quot;;\nconsole.log(!!name); \/\/ true\n\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst age = 0;\nconsole.log(!!age); \/\/ false  \/\/ \u6ce8\u610f 0 \u4e3a falsy\n\n<\/pre><\/div>\n\n\n<p>\u7528\u9014\uff1a\u8868\u5355\u6821\u9a8c\u3001\u5224\u65ad\u5b57\u6bb5\u662f\u5426\u4e3a\u7a7a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2b50 \u573a\u666f 2\uff1a\u5224\u65ad\u5bf9\u8c61\u6216\u6570\u7ec4\u662f\u5426\u4e3a\u7a7a<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5224\u65ad\u5bf9\u8c61\u662f\u5426\u6709\u6548<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst obj = {};\nconsole.log(!!Object.keys(obj).length); \/\/ false\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u5224\u65ad\u6570\u7ec4\u662f\u5426\u6709\u5185\u5bb9<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst arr = &#x5B;1,2];\nconsole.log(!!arr.length); \/\/ true\n\nconsole.log(!!&#x5B;].length); \/\/ false\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2b50 \u573a\u666f 3\uff1a\u4ece\u63a5\u53e3\u8fd4\u56de\u7684\u503c\u8f6c\u6362\u4e3a\u5e03\u5c14\u7c7b\u578b<\/h2>\n\n\n\n<p>\u6709\u4e9b\u63a5\u53e3\u4f1a\u8fd4\u56de <code>1<\/code> \/ <code>0<\/code> \u8868\u793a\u662f\u5426\u542f\u7528\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst apiValue = 1;\nconst enabled = !!apiValue;\n\nconsole.log(enabled); \/\/ true\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2b50 \u573a\u666f 4\uff1a\u907f\u514d if \u5185\u51fa\u73b0\u590d\u6742\u5224\u65ad<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nif (!!user &amp;amp;&amp;amp; !!user.name) {\n  console.log(&quot;\u7528\u6237\u5b58\u5728\u4e14\u6709\u540d\u5b57&quot;);\n}\n\n<\/pre><\/div>\n\n\n<p>\u7b49\u540c\u4e8e\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nif (user &amp;amp;&amp;amp; user.name) { ... }\n\n<\/pre><\/div>\n\n\n<p>\u4f46 <code>!!<\/code> \u5f3a\u5236\u8f6c\u6362\u6210\u5e03\u5c14\uff0c\u66f4\u8bed\u4e49\u5316\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2b50 \u573a\u666f 5\uff1a\u77ed\u8def\u8fd0\u7b97 + !! \u7684\u5e38\u7528\u6280\u5de7<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5c06\u53ef\u80fd\u4e3a null \u7684\u503c\u8f6c\u6362\u6210\u5e03\u5c14<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst isLogin = !!localStorage.getItem(&quot;token&quot;);\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u5224\u65ad DOM \u5143\u7d20\u662f\u5426\u5b58\u5728<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconst hasBtn = !!document.querySelector(&quot;#button&quot;);\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2705 \u4e94\u3001\u7279\u6b8a\u5751\u4f4d\u9700\u6ce8\u610f<\/h1>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u26a0\ufe0f 1. <code>!!0<\/code> \u59cb\u7ec8\u662f false<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconsole.log(!!0); \/\/ false\n\n<\/pre><\/div>\n\n\n<p>\u5982\u679c\u4f60\u7684\u5b57\u6bb5\u6709 \u201c0 \u4e5f\u7b97\u6709\u6548\u201d\uff0c\u5219\u4e0d\u8981\u7528 <code>!!<\/code>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u26a0\ufe0f 2. <code>!!\"\"<\/code> \u4f1a\u53d8 false\uff08\u7a7a\u5b57\u7b26\u4e32\uff09<\/h2>\n\n\n\n<p>\u6709\u65f6\u7a7a\u5b57\u7b26\u4e32\u4e5f\u88ab\u5f53\u4f5c\u6709\u6548\u8f93\u5165\uff0c\u6b64\u65f6\u4e0d\u80fd\u7528 <code>!!<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u26a0\ufe0f 3. <code>!![]<\/code> \u6c38\u8fdc\u662f true<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nconsole.log(!!&#x5B;]); \/\/ true\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u5224\u65ad\u6570\u7ec4\u662f\u5426\u4e3a\u7a7a\u5fc5\u987b\u7528 length\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n!!arr.length\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2705 \u516d\u3001\u4f60\u53ef\u4ee5\u8bb0\u4f4f\u7684\u7ec8\u6781\u603b\u7ed3<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u503c<\/th><th><code>!!<\/code> \u7ed3\u679c<\/th><th>\u610f\u4e49<\/th><\/tr><\/thead><tbody><tr><td>0\u3001&#8221;\u3001null\u3001undefined\u3001NaN\u3001false<\/td><td>false<\/td><td>\u65e0\u6548\u503c<\/td><\/tr><tr><td>\u5176\u4ed6\u6240\u6709\u503c\uff08\u5305\u62ec\u5bf9\u8c61\u3001\u6570\u7ec4\u3001\u51fd\u6570\uff09<\/td><td>true<\/td><td>\u6709\u503c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\ud83d\udc49 \u53cc\u91cd\u5426\u5b9a\u662f <strong>\u6700\u7b80\u6d01\u7684\u5e03\u5c14\u8f6c\u6362\u5de5\u5177<\/strong>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u7bc7 \u8d85\u6e05\u6670\u3001\u5e26\u793a\u4f8b\u3001\u9002\u5408\u65b0\u624b\u548c\u8fdb\u9636\u5f00\u53d1\u8005 \u7684 \u300aJavaScript &#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/05\/javascript%e5%8f%8c%e9%87%8d%e5%90%a6%e5%ae%9a%e8%bf%90%e7%ae%97%e7%9a%84%e5%85%b7%e4%bd%93%e4%bd%bf%e7%94%a8\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"class_list":["post-516","post","type-post","status-publish","format-standard","hentry","category-javascript"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=516"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/516\/revisions"}],"predecessor-version":[{"id":517,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/516\/revisions\/517"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}