{"id":3722,"date":"2024-11-10T12:01:21","date_gmt":"2024-11-10T04:01:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3722\/"},"modified":"2024-11-10T12:01:21","modified_gmt":"2024-11-10T04:01:21","slug":"es6-%e4%b8%ad-const-%e5%92%8c-let-%e7%9a%84%e5%8c%ba%e5%88%ab%ef%bc%9a%e5%b8%b8%e9%87%8f%e5%92%8c%e5%8f%98%e9%87%8f%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b9%89%e5%92%8c%e4%bd%bf%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3722\/","title":{"rendered":"ES6 \u4e2d const \u548c let \u7684\u533a\u522b\uff1a\u5e38\u91cf\u548c\u53d8\u91cf\u5982\u4f55\u5b9a\u4e49\u548c\u4f7f\u7528\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173112557576122.jpg\" class=\"aligncenter\" title=\"ES6 \u4e2d const \u548c let \u7684\u533a\u522b\uff1a\u5e38\u91cf\u548c\u53d8\u91cf\u5982\u4f55\u5b9a\u4e49\u548c\u4f7f\u7528\uff1f\u63d2\u56fe\" alt=\"ES6 \u4e2d const \u548c let \u7684\u533a\u522b\uff1a\u5e38\u91cf\u548c\u53d8\u91cf\u5982\u4f55\u5b9a\u4e49\u548c\u4f7f\u7528\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>ES6 \u5e38\u91cf\u4e0e\u53d8\u91cf\u7684<\/strong><\/p>\n<p>ES6 \u4e2d\u5f15\u5165\u4e86 const \u548c let \u4e24\u79cd\u53d8\u91cf\u58f0\u660e\u65b9\u5f0f\uff0cconst \u7528\u4e8e\u58f0\u660e\u5e38\u91cf\uff0c\u800c let \u7528\u4e8e\u58f0\u660e\u53d8\u91cf\u3002<\/p>\n<p><strong>\u5e38\u91cf const<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 const \u58f0\u660e\u7684\u53d8\u91cf\u4e3a\u4e0d\u53ef\u53d8\u5e38\u91cf\uff0c\u5373\u8d4b\u503c\u540e\u65e0\u6cd5\u4fee\u6539\u3002<\/li>\n<li>\u5e38\u91cf\u5fc5\u987b\u5728\u58f0\u660e\u65f6\u521d\u59cb\u5316\uff0c\u5426\u5219\u4f1a\u62a5\u9519\u3002<\/li>\n<\/ul>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0cconst PI = &#8216;3.14&#8217; \u5c06 PI \u58f0\u660e\u4e3a\u5e38\u91cf\uff0c\u56e0\u6b64\u4e0d\u80fd\u518d\u4f7f\u7528 PI = &#8216;3.15555&#8217; \u91cd\u65b0\u8d4b\u503c\u3002<\/p>\n<p><strong>\u53d8\u91cf let<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 let \u58f0\u660e\u7684\u53d8\u91cf\u4e3a\u53ef\u53d8\u53d8\u91cf\uff0c\u53ef\u4ee5\u968f\u65f6\u91cd\u65b0\u8d4b\u503c\u3002<\/li>\n<li>\u53d8\u91cf\u5fc5\u987b\u5728\u58f0\u660e\u65f6\u521d\u59cb\u5316\uff0c\u5426\u5219\u4f1a\u62a5\u9519\u3002<\/li>\n<\/ul>\n<p><strong>let \u548c const \u7684\u533a\u522b<\/strong><\/p>\n<p>\u5c3d\u7ba1 let \u548c const \u90fd\u5fc5\u987b\u5728\u4f7f\u7528\u524d\u521d\u59cb\u5316\uff0c\u4f46\u5b83\u4eec\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e<strong>\u53ef\u53d8\u6027<\/strong>\u3002const \u58f0\u660e\u7684\u5e38\u91cf\u4e0d\u53ef\u4fee\u6539\uff0c\u800c let \u58f0\u660e\u7684\u53d8\u91cf\u53ef\u4ee5\u4fee\u6539\u3002<\/p>\n<p><strong>let PI = &#8216;2222&#8217;<\/strong><\/p>\n<p>\u5728\u6b64\u4ee3\u7801\u4e2d\uff0c\u867d\u7136\u4f7f\u7528\u4e86 const \u5b9a\u4e49\u4e86 PI \u5e38\u91cf\uff0c\u4f46\u968f\u540e\u53c8\u4f7f\u7528 let \u58f0\u660e\u4e86\u4e00\u4e2a\u65b0\u7684\u5c40\u90e8\u53d8\u91cf PI\u3002\u7531\u4e8e let \u58f0\u660e\u7684\u53d8\u91cf\u53ef\u4ee5\u91cd\u65b0\u8d4b\u503c\uff0c\u56e0\u6b64\u4e0d\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u5c06 let PI = &#8216;2222&#8217; \u6539\u4e3a const PI = &#8216;2222&#8217;\uff0c\u5219\u4f1a\u62a5\u9519\uff0c\u56e0\u4e3a\u4e0d\u80fd\u91cd\u65b0\u8d4b\u503c const \u5e38\u91cf\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fES6 \u4e2d const \u548c let \u7684\uff1a\u5e38\u91cf\u548c\u53d8\u91cf\u5982\u4f55\u5b9a\u4e49\u548c\u4f7f\u7528\uff1f\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>ES6 \u5e38\u91cf\u4e0e\u53d8\u91cf\u7684 ES6 \u4e2d\u5f15\u5165\u4e86 const \u548c let \u4e24\u79cd\u53d8\u91cf\u58f0\u660e\u65b9\u5f0f\uff0cconst \u7528\u4e8e\u58f0\u660e\u5e38\u91cf\uff0c\u800c let \u7528\u4e8e\u58f0\u660e\u53d8\u91cf\u3002 \u5e38\u91cf const \u4f7f\u7528 const \u58f0\u660e\u7684\u53d8\u91cf\u4e3a\u4e0d\u53ef\u53d8\u5e38\u91cf\uff0c\u5373\u8d4b\u503c\u540e\u65e0\u6cd5\u4fee\u6539\u3002 \u5e38\u91cf\u5fc5\u987b\u5728\u58f0\u660e\u65f6\u521d\u59cb\u5316\uff0c\u5426\u5219\u4f1a\u62a5\u9519\u3002 \u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0cconst PI = &#8216;3.14&#8217; \u5c06 PI \u58f0\u660e\u4e3a\u5e38\u91cf\uff0c\u56e0\u6b64\u4e0d\u80fd\u518d\u4f7f\u7528 PI = &#8216;3.15555&#8217; \u91cd\u65b0\u8d4b\u503c\u3002 \u53d8\u91cf let \u4f7f\u7528 let \u58f0\u660e\u7684\u53d8\u91cf\u4e3a\u53ef\u53d8\u53d8\u91cf\uff0c\u53ef\u4ee5\u968f\u65f6\u91cd\u65b0\u8d4b\u503c\u3002 \u53d8\u91cf\u5fc5\u987b\u5728\u58f0\u660e\u65f6\u521d\u59cb\u5316\uff0c\u5426\u5219\u4f1a\u62a5\u9519\u3002 let \u548c const \u7684\u533a\u522b \u5c3d\u7ba1 let \u548c const \u90fd\u5fc5\u987b\u5728\u4f7f\u7528\u524d\u521d\u59cb\u5316\uff0c\u4f46\u5b83\u4eec\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u53ef\u53d8\u6027\u3002const \u58f0\u660e\u7684\u5e38\u91cf\u4e0d\u53ef\u4fee\u6539\uff0c\u800c let \u58f0\u660e\u7684\u53d8\u91cf\u53ef\u4ee5\u4fee\u6539\u3002 let PI = &#8216;2222&#8217; \u5728\u6b64\u4ee3\u7801\u4e2d\uff0c\u867d\u7136\u4f7f\u7528\u4e86 const \u5b9a\u4e49\u4e86 PI \u5e38\u91cf\uff0c\u4f46\u968f\u540e\u53c8\u4f7f\u7528 [&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-3722","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3722","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=3722"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3722\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}