{"id":52800,"date":"2024-12-03T09:30:55","date_gmt":"2024-12-03T01:30:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52800\/"},"modified":"2024-12-03T09:30:55","modified_gmt":"2024-12-03T01:30:55","slug":"%e6%8e%8c%e6%8f%a1-javascript-%e4%b8%ad%e7%9a%84%e9%80%bb%e8%be%91%e8%bf%90%e7%ae%97%e7%ac%a6%ef%bc%9a%e3%80%81-%e5%92%8c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52800\/","title":{"rendered":"\u638c\u63e1 JavaScript \u4e2d\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a`||`\u3001`&#038;&#038;` \u548c `!`"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u638c\u63e1 JavaScript \u4e2d\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a`||`\u3001`&amp;&amp;` \u548c `!`<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u638c\u63e1 JavaScript \u4e2d\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a`||`\u3001`&amp;&amp;` \u548c `!`\u300b<\/span>\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/173234920267418d1201bde.jpg\" class=\"aligncenter\" title=\"\u638c\u63e1 JavaScript \u4e2d\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a`||`\u3001`&#038;&#038;` \u548c `!`\u63d2\u56fe\" alt=\"\u638c\u63e1 JavaScript \u4e2d\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a`||`\u3001`&#038;&#038;` \u548c `!`\u63d2\u56fe\" \/><\/p>\n<p>\u5728\u672c\u535a\u5ba2\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8 javascript \u4e2d\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a<strong>||<\/strong> (or)\u3001<strong>&amp;&amp;<\/strong> (and) \u548c <strong>!<\/strong> (not) \uff09\u3002\u8fd9\u4e9b\u8fd0\u7b97\u7b26\u5bf9\u4e8e\u521b\u5efa\u590d\u6742\u6761\u4ef6\u548c\u63a7\u5236\u7a0b\u5e8f\u6d41\u7a0b\u81f3\u5173\u91cd\u8981\u3002\u8ba9\u6211\u4eec\u6f5c\u5165\u5427\uff01<\/p>\n<h3> <strong>\u903b\u8f91\u8fd0\u7b97\u7b26&nbsp;||&nbsp;\uff08\u6216\uff09<\/strong> <\/h3>\n<p><strong>||<\/strong> \u8fd0\u7b97\u7b26\u8fd4\u56de\u5b83\u9047\u5230\u7684\u7b2c\u4e00\u4e2a\u771f\u503c\u3002\u5982\u679c\u6240\u6709\u503c\u90fd\u662f\u5047\u7684\uff0c\u5219\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u503c\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>result = value1 || value2 || value3;\n\n<\/pre>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>let a = false;\nlet b = null;\nlet c = \"hello\";\n\nlet result = a || b || c;\nconsole.log(result); \/\/ output: \"hello\"\n\n<\/pre>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>a<\/strong>&nbsp;\u662f<strong>\u5047<\/strong>&nbsp;\uff08\u5047\uff09\u3002<\/li>\n<li> <strong>b<\/strong>&nbsp;\u4e3a <strong>null<\/strong>&nbsp;\uff08\u5047\uff09\u3002<\/li>\n<li> <strong>c<\/strong>&nbsp;\u662f<strong>\u201c\u4f60\u597d\u201d<\/strong>&nbsp;\uff08\u771f\u5b9e\uff09\u3002<\/li>\n<\/ul>\n<p><strong>||<\/strong> \u8fd0\u7b97\u7b26\u8fd4\u56de\u7b2c\u4e00\u4e2a\u771f\u503c\uff0c\u5373 <strong>&#8220;hello&#8221;<\/strong>.<\/p>\n<h3> <strong>\u903b\u8f91\u8fd0\u7b97\u7b26 &amp;&amp; (and)<\/strong> <\/h3>\n<p><strong>&amp;&amp;<\/strong> \u8fd0\u7b97\u7b26\u8fd4\u56de\u5b83\u9047\u5230\u7684\u7b2c\u4e00\u4e2a\u5047\u503c\u3002\u5982\u679c\u6240\u6709\u503c\u5747\u4e3a\u771f\uff0c\u5219\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u503c\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>result = value1 &amp;&amp; value2 &amp;&amp; value3;\n\n<\/pre>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>let x = true;\nlet y = 10;\nlet z = 0;\n\nlet result = x &amp;&amp; y &amp;&amp; z;\nconsole.log(result); \/\/ output: 0\n\n<\/pre>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>x<\/strong>&nbsp;\u4e3a <strong>true<\/strong>&nbsp;\uff08\u771f\u5b9e\uff09\u3002<\/li>\n<li> <strong>y<\/strong>&nbsp;\u662f&nbsp;<strong>10<\/strong>&nbsp;\uff08\u771f\u5b9e\uff09\u3002<\/li>\n<li> <strong>z<\/strong>&nbsp;\u662f&nbsp;<strong>0<\/strong>&nbsp;\uff08\u5047\uff09\u3002<\/li>\n<\/ul>\n<p><strong>&amp;&amp;<\/strong> \u8fd0\u7b97\u7b26\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5047\u503c\uff0c\u5373 <strong>0<\/strong>.<\/p>\n<h3> <strong>\u903b\u8f91\u8fd0\u7b97\u7b26\uff01&nbsp;\uff08\u4e0d\u662f\uff09<\/strong> <\/h3>\n<p><strong>!<\/strong> \u8fd0\u7b97\u7b26\u8fd4\u56de\u5176\u64cd\u4f5c\u6570\u7684\u76f8\u53cd\u5e03\u5c14\u503c\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>result = !value;\n\n<\/pre>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>let istrue = true;\nlet isfalse = !istrue;\n\nconsole.log(isfalse); \/\/ output: false\n\n<\/pre>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u4e3a\u771f<\/strong>&nbsp;\u4e3a<strong>\u771f<\/strong>\u3002<\/li>\n<li> <strong>!istrue<\/strong>&nbsp;\u8fd4\u56de<strong>false<\/strong>\u3002<\/li>\n<\/ul>\n<h3> <strong>\u5b9e\u9645\u4f8b\u5b50<\/strong> <\/h3>\n<p>\u8ba9\u6211\u4eec\u7528\u4e00\u4e9b\u5b9e\u9645\u4f8b\u5b50\u5c06\u6240\u6709\u5185\u5bb9\u653e\u5728\u4e00\u8d77\uff1a<\/p>\n<h3> <strong>\u4f7f\u7528||&nbsp;\u5bf9\u4e8e\u9ed8\u8ba4\u503c<\/strong> <\/h3>\n<pre>function greet(name) {\n  name = name || \"guest\";\n  console.log(\"hello, \" + name + \"!\");\n}\n\ngreet(\"alice\"); \/\/ output: hello, alice!\ngreet(); \/\/ output: hello, guest!\n\n<\/pre>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u672a\u63d0\u4f9b<strong>\u540d\u79f0<\/strong>\uff0c\u5219<strong>||<\/strong>\u8fd0\u7b97\u7b26\u4f1a\u5206\u914d\u9ed8\u8ba4\u503c<strong>\u201cguest\u201d<\/strong>\u3002<\/li>\n<\/ul>\n<h3> <strong>\u4f7f\u7528 &amp;&amp; \u8fdb\u884c\u6761\u4ef6\u6267\u884c<\/strong> <\/h3>\n<pre>let user = {\n  name: \"john\",\n  age: 25,\n  isadmin: true\n};\n\nif (user.isadmin &amp;&amp; user.age &gt; 18) {\n  console.log(\"welcome, admin!\");\n} else {\n  console.log(\"welcome, user!\");\n}\n\n<\/pre>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li><strong>&amp;&amp;<\/strong>&nbsp;\u8fd0\u7b97\u7b26\u68c0\u67e5\u4e24\u4e2a\u6761\u4ef6\uff08<strong>user.isadmin<\/strong>&nbsp;\u548c<strong>user.age &gt; 18<\/strong>\uff09\u662f\u5426\u90fd\u4e3a\u771f\u3002<\/li>\n<\/ul>\n<h3> <strong>\u4f7f\u7528\uff01&nbsp;\u5bf9\u4e8e\u5426\u5b9a<\/strong> <\/h3>\n<pre>let isLoggedIn = false;\n\nif (!isLoggedIn) {\n  console.log(\"Please log in.\");\n} else {\n  console.log(\"Welcome back!\");\n}\n\n<\/pre>\n<p><strong>\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li><strong>!<\/strong> \u8fd0\u7b97\u7b26\u5bf9 <strong>isloggedin<\/strong> \u7684\u503c\u53d6\u53cd\u3002\u5982\u679c <strong>isloggedin<\/strong> \u4e3a <strong>false<\/strong>\uff0c\u5219 <strong>!isloggedin<\/strong> \u4e3a <strong>true<\/strong>\u3002<\/li>\n<\/ul>\n<h3> <strong>\u603b\u7ed3<\/strong> <\/h3>\n<ul>\n<li> <strong>||&nbsp;(or)<\/strong>\uff1a\u8fd4\u56de\u7b2c\u4e00\u4e2a\u771f\u503c\u6216\u6700\u540e\u4e00\u4e2a\u503c\uff08\u5982\u679c\u6240\u6709\u503c\u5747\u4e3a\u5047\u503c\uff09\u3002<\/li>\n<li> <strong>&amp;&amp;&nbsp;(and)<\/strong>\uff1a\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5047\u503c\u6216\u6700\u540e\u4e00\u4e2a\u503c\uff08\u5982\u679c\u6240\u6709\u503c\u5747\u4e3a\u771f\u503c\uff09\u3002<\/li>\n<li> <strong>\uff01&nbsp;(not)<\/strong>\uff1a\u8fd4\u56de\u5176\u64cd\u4f5c\u6570\u7684\u76f8\u53cd\u5e03\u5c14\u503c\u3002<\/li>\n<\/ul>\n<h3> <strong>\u7ed3\u8bba<\/strong> <\/h3>\n<p>\u903b\u8f91\u8fd0\u7b97\u7b26\u662f javascript \u4e2d\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u8ba9\u60a8\u521b\u5efa\u590d\u6742\u7684\u6761\u4ef6\u5e76\u63a7\u5236\u7a0b\u5e8f\u7684\u6d41\u7a0b\u3002\u901a\u8fc7\u638c\u63e1 <strong>||<\/strong>\u3001<strong>&amp;&amp;<\/strong> \u548c <strong>!<\/strong>\uff0c\u60a8\u5c06\u80fd\u591f\u7f16\u5199\u66f4\u52a8\u6001\u3001\u66f4\u9ad8\u6548\u7684\u4ee3\u7801\u3002\u4e0d\u65ad\u7ec3\u4e60\u548c\u63a2\u7d22\uff0c\u52a0\u6df1\u5bf9 javascript \u4e2d\u903b\u8f91\u8fd0\u7b97\u7b26\u7684\u7406\u89e3\u3002<\/p>\n<p>\u8bf7\u7ee7\u7eed\u5173\u6ce8\u6709\u5173 javascript \u7684\u66f4\u591a\u6df1\u5165\u535a\u5ba2\uff01\u5feb\u4e50\u7f16\u7801\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664    <\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   Element-UI Cascader \u591a\u9009\u6027\u80fd\u4f18\u5316\uff1a\u5982\u4f55\u517c\u987e\u6570\u636e\u5b8c\u6574\u6027\u548c\u6e32\u67d3\u6548\u7387\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u638c\u63e1 JavaScript \u4e2d\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a`||`\u3001`&amp;&amp;` \u548c `!` \u6536\u85cf \u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587\u300a\u638c\u63e1 JavaScript \u4e2d\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a`||`\u3001`&amp;&amp;` \u548c `!`\u300b\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0\u6587\u7ae0\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01 \u5728\u672c\u535a\u5ba2\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8 javascript \u4e2d\u7684\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a|| (or)\u3001&amp;&amp; (and) \u548c ! (not) \uff09\u3002\u8fd9\u4e9b\u8fd0\u7b97\u7b26\u5bf9\u4e8e\u521b\u5efa\u590d\u6742\u6761\u4ef6\u548c\u63a7\u5236\u7a0b\u5e8f\u6d41\u7a0b\u81f3\u5173\u91cd\u8981\u3002\u8ba9\u6211\u4eec\u6f5c\u5165\u5427\uff01 \u903b\u8f91\u8fd0\u7b97\u7b26&nbsp;||&nbsp;\uff08\u6216\uff09 || \u8fd0\u7b97\u7b26\u8fd4\u56de\u5b83\u9047\u5230\u7684\u7b2c\u4e00\u4e2a\u771f\u503c\u3002\u5982\u679c\u6240\u6709\u503c\u90fd\u662f\u5047\u7684\uff0c\u5219\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u503c\u3002 \u8bed\u6cd5\uff1a result = value1 || value2 || value3; \u793a\u4f8b\uff1a let a = false; let b = null; let c = &#8220;hello&#8221;; let result = a || b || c; console.log(result); \/\/ output: [&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-52800","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52800","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=52800"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52800\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}