{"id":69,"date":"2023-07-20T14:59:54","date_gmt":"2023-07-20T06:59:54","guid":{"rendered":"https:\/\/iwebg.cn\/?p=69"},"modified":"2023-07-20T15:03:01","modified_gmt":"2023-07-20T07:03:01","slug":"%e5%89%8d%e7%ab%af%e4%bb%a3%e7%a0%81%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"http:\/\/iwebg.cn\/index.php\/2023\/07\/20\/%e5%89%8d%e7%ab%af%e4%bb%a3%e7%a0%81%e4%bc%98%e5%8c%96\/","title":{"rendered":"\u524d\u7aef\u4ee3\u7801\u4f18\u5316"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">1.\u5e26\u6709\u591a\u7684\u6761\u4ef6\u7684if\u7684\u8bed\u53e5 \u903b\u8f91 || \u7684\u7b80\u5199<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>if (x == 'true' || x == '2523' || x == '\u5c0f\u660e') {\n    \/\/ logic\n}\n\n\/\/Array.includes() \u65b9\u6cd5\u7528\u6765\u5224\u65ad\u4e00\u4e2a\u6570\u7ec4\u662f\u5426\u5305\u542b\u4e00\u4e2a\u6307\u5b9a\u7684\u503c\uff0c\u6839\u636e\u60c5\u51b5\uff0c\u5982\u679c\u5305\u542b\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\nif (&#91;'true', '2523', '\u5c0f\u660e'].includes(x)) {\n    \/\/ logic\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.\u7b80\u5316 if true\u2026else \u6761\u4ef6\u7684\u5199\u6cd5\uff0c\u53ef\u4ee5\u8fd0\u7528\u4e09\u5143\u8fd0\u7b97\u7b26<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>if (x &gt; 100) {\n    test = true\n} else {\n    test = false\n}\n\ntest = x &gt; 100 ? true : false<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.\u58f0\u660e\u53d8\u91cf<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let test1;\nlet test2 = 1\n\/\/ \u7b80\u5199\nlet test3, test4 = 1\n\n\/\/ \u7ed9\u591a\u4e2a\u53d8\u91cf\u8fdb\u884c\u8d4b\u503c\nlet test1 = 1, test3 = 2, test4 = 3;\n\/\/ \u7b80\u5316 \nlet &#91;test1, test3, test4] = &#91;1, 2, 3]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4.null \u548c undefined \u7684\u7a7a\u7f6e\u68c0\u67e5\u5f53\u8fd9\u4e2a\u6570\u636e\u5df2\u77e5\u662f null \u6216\u8005\u662f undefined \u53ef\u4ee5\u8fd9\u6837\u5199<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>if (test1 != null || test1 !== undefined || test1 !== '') {\n    \/\/ logic\n    let test2 = test1\n}\nlet test2 = test1 || ''\n\n\/\/ \u8fd8\u53ef\u4ee5\u57fa\u4e8e ?? \u64cd\u4f5c\u7b26 \u5982\u679c\u5de6\u8fb9\u7684\u503c\u4e3a null \u6216 undefined \u5c31\u8fd4\u56de\u53f3\u8fb9\u7684\u503c\uff0c\u5982\u679c\u5de6\u8fb9\u7684\u503c\u4e3a\u9ed8\u8ba4\u503c\u5c31\u8fd4\u56de\u5de6\u8fb9\u7684\u503c\nconst test = null ?? 'default'\nconsole.log(test) \/\/ default\n\n\/\/ || \u4e0e ?? \u5224\u65ad\u7684\u65b9\u6cd5\u4e0d\u540c\uff1a\n\/\/ \u4f7f\u7528 ?? \u65f6\uff0c\u53ea\u6709One\u4e3a null \u6216\u8005 undefined \u65f6\u624d\u4f1a\u8fd4\u56de Two;\n\/\/ \u4f7f\u7528 || \u65f6\uff0cOne\u4f1a\u5148\u8f6c\u5316\u4e3a\u5e03\u5c14\u503c\u5224\u65ad\uff0c\u4e3atrue\u65f6\u8fd4\u56deOne , false \u8fd4\u56deTwo\nconst test6 = 0 ?? 1\nconsole.log(test6) \/\/ 0<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5.\u64cd\u4f5c\u8d4b\u503c\u7b26<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let test1 = 3\ntest1 = test1 + 1\ntest3 = test1 - 1\ntest4 = test1 * 20\n\n\/\/ \u7b80\u5316\ntest1++\ntest1--\ntest1 *= 20<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6.\u5224\u65ad\u503c\u662f\u5426\u5b58\u5728<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>if (val) { } \/\/ \u5b58\u5728 \nif (!val) { }  \/\/ \u4e0d\u5b58\u5728<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7.\u6761\u4ef6\u5224\u65ad &amp;&amp; \u5224\u65ad\u5982\u679c\u4e3a true \u8c03\u7528\u51fd\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>if (test1) {\n    fn()\n}\n\/\/test1 \u4e3atrue  \u6267\u884c fn()\ntest1 &amp;&amp; fn()\n\/\/test1 \u4e3afalse \u6267\u884c fn()\ntest1 || fn()<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">8.\u62fc\u63a5\u7b80\u5316<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let arr1 = &#91;1, 3]\nlet arr2 = &#91;4, 5]\nconsole.log(arr2.concat(arr1))\nconsole.log(&#91;...arr1, ...arr2])<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">9.\u514b\u9686\u6570\u7ec4<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>let arr4 = &#91;1, 234, 4, 88]\nlet arr5 = arr4.slice()\n\nlet arr4 = &#91;1, 234, 4, 88]\nlet arr5 = &#91;...arr4]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">10.switch \u7684\u7b80\u5316<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>function fn1() { console.log(1) }\nfunction fn2() { console.log(2) }\nfunction fn3() { console.log(3) }\nlet data1 = 1\nswitch (data1) {\n    case 1:\n        fn1()\n        break\n    case 2:\n        fn2()\n        break\n    case 'h':\n        fn3()\n        break\n    default:\n        console.log('\u5565\u4e5f\u662f\u4e0d\u662f')\n}\n\n\/\/ \u7b80\u5316\nlet data2 = 1\nvar data = {\n    1: fn1,\n    2: fn2,\n    'h': fn3,\n}\ndata&#91;data2] &amp;&amp; data&#91;data2]()<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">11.Object.assign()\u8bbe\u7f6e\u9ed8\u8ba4\u5bf9\u8c61<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>const menuConfig = {\n  title: null,\n  body: 'Bar',\n  buttonText: null,\n  cancellable: true\n};\n\nfunction createMenu(config) {\n  config.title = config.title || 'Foo';\n  config.body = config.body || 'Bar';\n  config.buttonText = config.buttonText || 'Baz';\n  config.cancellable = config.cancellable === undefined ? config.cancellable : true;\n}\n\ncreateMenu(menuConfig);\n\n-----------------------------\n\nconst menuConfig = {\n  title: 'Order',\n  \/\/ User did not include 'body' key\n  buttonText: 'Send',\n  cancellable: true\n};\n\nfunction createMenu(config) {\n  config = Object.assign({\n    title: 'Foo',\n    body: 'Bar',\n    buttonText: 'Baz',\n    cancellable: true\n  }, config);\n\n  \/\/ config now equals: {title: \"Order\", body: \"Bar\", buttonText: \"Send\", cancellable: true}\n  \/\/ ...\n}\n\ncreateMenu(menuConfig);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">12.\u4f7f\u7528\u53ef\u641c\u7d22\u7684\u540d\u79f0<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u8279\uff0c 86400000 \u662f\u4ec0\u4e48\u9b3c\uff1f\nsetTimeout(blastOff, 86400000);\n\n\/\/ \u5c06\u5b83\u4eec\u58f0\u660e\u4e3a\u5168\u5c40\u5e38\u91cf `const` \u3002\nconst MILLISECONDS_IN_A_DAY = 86400000;\nsetTimeout(blastOff, MILLISECONDS_IN_A_DAY);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">13.\u4f7f\u7528\u89e3\u91ca\u6027\u7684\u53d8\u91cf<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>const address = 'One Infinite Loop, Cupertino 95014';\nconst cityZipCodeRegex = \/^&#91;^,\\\\]+&#91;,\\\\\\s]+(.+?)\\s*(\\d{5})?$\/;\nsaveCityZipCode(address.match(cityZipCodeRegex)&#91;1], address.match(cityZipCodeRegex)&#91;2]);\n\nconst address = 'One Infinite Loop, Cupertino 95014';\nconst cityZipCodeRegex = \/^&#91;^,\\\\]+&#91;,\\\\\\s]+(.+?)\\s*(\\d{5})?$\/;\nconst &#91;city, zipCode] = address.match(cityZipCodeRegex) || &#91;];\nsaveCityZipCode(city, zipCode);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">14.\u4f7f\u7528\u9ed8\u8ba4\u53d8\u91cf\u66ff\u4ee3\u77ed\u8def\u8fd0\u7b97\u6216\u6761\u4ef6<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>function createMicrobrewery(name) {\n  const breweryName = name || 'Hipster Brew Co.';\n  \/\/ ...\n}\n\nfunction createMicrobrewery(breweryName = 'Hipster Brew Co.') {\n  \/\/ ...\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">15,\u51fd\u6570\u53c2\u6570 (\u4e24\u4e2a\u4ee5\u4e0b\u6700\u7406\u60f3)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>function createMenu(title, body, buttonText, cancellable) {\n  \/\/ ...\n}\n\nconst menuConfig = {\n  title: 'Foo',\n  body: 'Bar',\n  buttonText: 'Baz',\n  cancellable: true\n};\n\nfunction createMenu(config) {\n  \/\/ ...\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">16.\u4f7f\u7528\u89e3\u6784\u8d4b\u503c \u89e3\u6784\u5bf9\u8c61\u91cc\u7684\u5c5e\u6027<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>async Fn1(){\n    const res = await getData() \/\/ \u9700\u7528res.data\u624d\u80fd\u4f7f\u7528\n    const { data: res } = await getData() \/\/ \u7ed3\u6784\u6570\u636e\u91cc\u7684data\u8d4b\u503c\u7ed9res\n}\n\nthat.wechat.name = res.data.weixin.name || ''\nthat.wechat.payAccount = res.data.weixin.payAccount || ''\nthat.wechat.phone = res.data.weixin.phone || ''\n\/\/\u89e3\u6784\u8d4b\u503c\u5bf9\u8c61\u4f18\u5316 \u6ce8\u610f\u4e0a\u4e0b\u6587\u5206\u53f7\n({name:that.alipay.name,phone: that.alipay.phone, payAccount: that.alipay.payAccount} = res.data.alipay);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">17.\u6570\u7ec4\u6241\u5e73\u5316<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u4f7f\u7528 Infinity\uff0c\u53ef\u5c55\u5f00\u4efb\u610f\u6df1\u5ea6\u7684\u5d4c\u5957\u6570\u7ec4\nvar arr4 = &#91;1, 2, &#91;3, 4, &#91;5, 6, &#91;7, 8, &#91;9, 10]]]]];\narr4.flat(Infinity);\n\/\/ &#91;1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">18.\u63d0\u524d\u9000\u51fa \u548c \u63d0\u524d\u8fd4\u56de<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>function printAnimalsDetails(animal) {\n    var result = null\n    if (animal) {\n        if (animal.type) {\n            if (animal.name) {\n                if (animal.gender) {\n                    result = `${animal.name} is a ${animal.gender} - ${animal.\n                        type}`\n                } else {\n                    result = 'no anomal gender'\n                }\n            } else {\n                result = 'no animal name'\n            }\n        } else {\n            result = 'no animal type'\n        }\n    } else {\n        result = 'no animal'\n    }\n    return result\n}\n\n\/\/ \u63d0\u524d\u9000\u51fa \u548c \u63d0\u524d\u8fd4\u56de\nconst printAnimalsDetails = (animal) =&gt; {\n    if (!animal.type) return \"no animal type\"\n    if (!animal.name) return \"no animal name\"\n    if (!animal.gender) return \"no animal gender\"\n    return `${animal.name} is a ${animal.gender} - ${animal.type}`\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1.\u5e26\u6709\u591a\u7684\u6761\u4ef6\u7684if\u7684\u8bed\u53e5 \u903b\u8f91 || \u7684\u7b80\u5199 2.\u7b80\u5316 if true\u2026else \u6761\u4ef6\u7684\u5199\u6cd5\uff0c\u53ef\u4ee5\u8fd0\u7528\u4e09\u5143 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[12],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-10","tag-12"],"_links":{"self":[{"href":"http:\/\/iwebg.cn\/index.php\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/iwebg.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iwebg.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iwebg.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iwebg.cn\/index.php\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":10,"href":"http:\/\/iwebg.cn\/index.php\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":79,"href":"http:\/\/iwebg.cn\/index.php\/wp-json\/wp\/v2\/posts\/69\/revisions\/79"}],"wp:attachment":[{"href":"http:\/\/iwebg.cn\/index.php\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iwebg.cn\/index.php\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iwebg.cn\/index.php\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}