{"id":1476,"date":"2022-07-10T23:10:02","date_gmt":"2022-07-10T15:10:02","guid":{"rendered":"https:\/\/zhuxinyong.com\/?p=1476"},"modified":"2022-08-13T06:04:36","modified_gmt":"2022-08-12T22:04:36","slug":"30-javascript-zhong-de-yan-ge-mo-shi","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=1476","title":{"rendered":"30 &#8211; JavaScript \u4e2d\u7684\u4e25\u683c\u6a21\u5f0f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/08\/16574658222061.jpg\" alt=\"\" \/><\/p>\n<p>\u539f\u6587\u5730\u5740\uff1a<a href=\"https:\/\/dev.to\/bhagatparwinder\/strict-mode-in-javascript-4ge4\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.to\/bhagatparwinder\/strict-mode-in-javascript-4ge4<\/a><\/p>\n<p>ES5 \u4e2d\u5f15\u5165\u4e25\u683c\u6a21\u5f0f\uff0c\u5b83\u662f\u4e00\u79cd\u5728\u5199 JS \u4ee3\u7801\u65f6\u5f3a\u5236\u4f7f\u7528\u4e25\u683c\u6a21\u5f0f\u7684\u65b9\u6cd5\uff0c\u5e76\u4e0d\u662f\u6240\u6709\u7684\u6d4f\u89c8\u5668\u90fd\u652f\u6301\u4e25\u683c\u6a21\u5f0f\uff0c\u6240\u4ee5\u4f60\u9700\u8981\u4e3a\u4ee3\u7801\u6dfb\u52a0\u6d4b\u8bd5\u7528\u4f8b\u3002<\/p>\n<h2><a id=\"%E4%BC%98%E5%8A%BF\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4f18\u52bf<\/h2>\n<ol>\n<li>\u7981\u6b62\u9759\u9ed8\u9519\u8bef\u53d6\u800c\u4ee3\u4e4b\u7684\u662f\u629b\u51fa\u5b83\u4eec\u3002<\/li>\n<li>\u5728JS\u5f15\u64ce\u652f\u6301\u6027\u80fd\u4f18\u5316\u7684\u7279\u5b9a\u60c5\u51b5\u4e0b\u4f7f\u7528\u9ad8\u6027\u80fd\u4ee3\u7801\u3002<\/li>\n<li>\u4ee3\u7801\u63d0\u5347\n<ul>\n<li>\u5bf9\u8c61\u4e2d\u4e0d\u5b58\u5728\u91cd\u590d key<\/li>\n<li>\u58f0\u660e\u53d8\u91cf\u4e0d\u4f7f\u7528 <code>var<\/code> \u5173\u952e\u5b57<\/li>\n<li>\u51fd\u6570\u53c2\u6570\u4e0d\u5b58\u5728\u91cd\u590d\u53c2\u6570<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2><a id=\"%E5%BC%80%E5%90%AF%E4%B8%A5%E6%A0%BC%E6%A8%A1%E5%BC%8F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5f00\u542f\u4e25\u683c\u6a21\u5f0f<\/h2>\n<ul>\n<li><strong>\u6587\u4ef6\u7ea7\u522b\uff1a<\/strong> \u5728\u6587\u4ef6\u5f00\u5934\u5904\u6dfb\u52a0 <code>&quot;use strict&quot;<\/code>\u3002<\/li>\n<li><strong>\u51fd\u6570\u7ea7\u522b\uff1a<\/strong> \u5728\u51fd\u6570\u4f53\u7684\u6700\u524d\u9762\u6dfb\u52a0 <code>&quot;use strict&quot;<\/code>\u3002<\/li>\n<li><strong>\u6a21\u5757\u7ea7\u522b\uff1a<\/strong> ES6\/ES2015 \u5f15\u5165\u7684\u6a21\u5757\u9ed8\u8ba4\u5c31\u662f\u4e25\u683c\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<h2><a id=\"%E4%B8%A5%E6%A0%BC%E6%A8%A1%E5%BC%8F%E5%B8%A6%E6%9D%A5%E7%9A%84%E5%8F%98%E5%8C%96\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4e25\u683c\u6a21\u5f0f\u5e26\u6765\u7684\u53d8\u5316<\/h2>\n<p>1.\u6ca1\u6709\u4f7f\u7528 <code>var<\/code> \u5173\u952e\u5b57\u58f0\u660e\u7684\u53d8\u91cf<\/p>\n<pre><code class=\"language-plain_text\"> someVariable = 17;\n console.log(someVariable); \/\/ 17\n<\/code><\/pre>\n<p>\u8fd9\u662f\u4e00\u6bb5\u5408\u6cd5\u7684\u4ee3\u7801\uff0c\u5373\u4f7f\u6211\u4eec\u6ca1\u6709\u4f7f\u7528 <code>let<\/code>\u3001<code>var<\/code> \u6216 <code>const<\/code> \u53bb\u58f0\u660e\u53d8\u91cf\uff0cJavaScript \u4e2d\u4e5f\u4e0d\u4f1a\u6709\u95ee\u9898\u3002\u8fd9\u6837\u4f1a\u5f3a\u5236\u4f7f JS \u521b\u5efa\u4e00\u4e2a\u5168\u5c40\u7684\u5c5e\u6027\uff0c\u540c\u65f6\u5728\u5e94\u7528\u4e2d\u8fd9\u6837\u4f1a\u5bfc\u81f4\u4e00\u4e9b\u95ee\u9898\uff08\u53d8\u91cf\u51b2\u7a81\u6216\u66f4\u6539\u4e86\u5168\u5c40\u5c5e\u6027\uff09\u3002<\/p>\n<p>\u4e25\u683c\u6a21\u5f0f\u4f1a\u901a\u8fc7\u629b\u51fa\u9519\u8bef\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n<ol>\n<li>\u5bf9\u8c61\u4e2d\u4e0d\u4f1a\u6709\u91cd\u590d key<\/li>\n<\/ol>\n<pre><code class=\"language-plain_text\">  const myObject = {\n        name: &quot;Parwinder&quot;,\n        age: 34,\n        car: &quot;MiniCoop&quot;,\n        name: &quot;Bhagat&quot;\n    }\n   console.log(myObject.name); \/\/ Bhagat\n<\/code><\/pre>\n<p>\u7136\u800c\u5728\u975e\u4e25\u683c\u6a21\u5f0f\uff08\u677e\u6563\u6a21\u5f0f\uff09\u4e0b\u662f\u5b8c\u5168\u5408\u6cd5\u7684\uff0c\u4f46\u5728\u4e25\u683c\u6a21\u5f0f\u4e0b\u4f1a\u629b\u51fa\u9519\u8bef\u3002<\/p>\n<ol start=\"2\">\n<li>\u5220\u9664\u5bf9\u8c61\u4e0a\u4e0d\u53ef\u5220\u9664\u7684\u5c5e\u6027\u65f6\u62a5\u9519<\/li>\n<\/ol>\n<pre><code class=\"language-plain_text\"> &quot;use strict&quot;\n   delete Object.prototype; \/\/ throws a TypeError\n<\/code><\/pre>\n<ol start=\"3\">\n<li>\u51fd\u6570\u53c2\u6570\u4e0d\u5141\u8bb8\u91cd\u590d<\/li>\n<\/ol>\n<pre><code class=\"language-plain_text\">   function sumOfNumbers(a, a, b) {\n       return a + a + b;\n   }\n\n   console.log(sumOfNumbers(1, 2, 3)); \/\/ 7\n<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5728\u975e\u4e25\u683c\u6a21\u5f0f\u4e0b\u4e5f\u662f\u5408\u6cd5\u7684\uff0c\u4f46\u4f1a\u5bfc\u81f4\u4e00\u4e9b\u610f\u6599\u4e4b\u5916\u7684\u95ee\u9898\u3002 2 \u8d4b\u503c\u7ed9 <code>a<\/code> \uff0c\u4f46\u662f\u7ed3\u679c\u8fd4\u56de\u7684\u662f 7 \u800c\u4e0d\u662f\u9884\u671f\u7684 6 \u3002\u4e25\u683c\u6a21\u5f0f\u4e0b\u5c06\u4f1a\u62a5\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<ol>\n<li>\u975e\u4e25\u683c\u6a21\u5f0f\u4e0b\u628a NaN \u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\u4e0d\u4f1a\u6709\u9519\u8bef\u53cd\u9988\uff0c\u800c\u4e25\u683c\u6a21\u5f0f\u4f1a\u629b\u51fa\u9519\u8bef\u3002<\/li>\n<\/ol>\n<p>\u6ce8\u610f\uff1a\u6ca1\u6709\u529e\u6cd5\u53d6\u6d88\u201c\u4e25\u683c\u6a21\u5f0f\u201d\uff1a\u4e00\u65e6\u8fdb\u5165\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c\u6ca1\u6709\u529e\u6cd5\u628a\u5b83\u5173\u95ed\u6389\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740\uff1ahttps:\/\/dev.to\/bhagatparwinder\/strict-mode-in&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,20,3],"tags":[206],"class_list":["post-1476","post","type-post","status-publish","format-standard","hentry","category-all","category-frontend","category-tech","tag-206"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1476"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1476\/revisions"}],"predecessor-version":[{"id":1477,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1476\/revisions\/1477"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}