{"id":4082,"date":"2024-11-10T11:06:15","date_gmt":"2024-11-10T03:06:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/4082\/"},"modified":"2024-11-10T11:06:15","modified_gmt":"2024-11-10T03:06:15","slug":"js%e5%8f%98%e9%87%8f%e5%a3%b0%e6%98%8e%ef%bc%9avar%e4%b8%8elet%e6%9c%89%e4%bd%95%e5%8c%ba%e5%88%ab%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/4082\/","title":{"rendered":"JS\u53d8\u91cf\u58f0\u660e\uff1avar\u4e0elet\u6709\u4f55\u533a\u522b\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173122236435299.jpg\" class=\"aligncenter\" title=\"JS\u53d8\u91cf\u58f0\u660e\uff1avar\u4e0elet\u6709\u4f55\u533a\u522b\uff1f\u63d2\u56fe\" alt=\"JS\u53d8\u91cf\u58f0\u660e\uff1avar\u4e0elet\u6709\u4f55\u533a\u522b\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>JS\u4e2d\u7684\u53d8\u91cf\u58f0\u660e\u5173\u952e\u5b57var\u4e0elet\u8be6\u89e3<\/strong><\/p>\n<p>\u5728JavaScript\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528var\u548clet\u5173\u952e\u5b57\u6765\u58f0\u660e\u548c\u5b9a\u4e49\u53d8\u91cf\u3002\u7136\u800c\uff0c\u5b83\u4eec\u4e4b\u95f4\u5b58\u5728\u7740\u5173\u952e\u3002<\/p>\n<p><strong>var\u5173\u952e\u5b57<\/strong><\/p>\n<ul>\n<li>var\u5173\u952e\u5b57\u58f0\u660e\u7684\u662f<strong>\u5168\u5c40\u53d8\u91cf<\/strong>\uff0c\u53ef\u4ee5\u5728\u7a0b\u5e8f\u7684\u4efb\u4f55\u5730\u65b9\u8bbf\u95ee\u3002<\/li>\n<li>\u4f7f\u7528var\u58f0\u660e\u7684\u53d8\u91cf\u5728\u53d8\u91cf<strong>\u58f0\u660e<\/strong>\u524d\u4e5f\u53ef\u4ee5\u8bbf\u95ee\uff08\u58f0\u660e\u63d0\u5347\uff09\u3002<\/li>\n<li>var\u58f0\u660e\u7684\u53d8\u91cf\u5141\u8bb8<strong>\u91cd\u590d\u58f0\u660e<\/strong>\uff0c\u4f46\u4f1a\u8986\u76d6\u4e4b\u524d\u7684\u58f0\u660e\u3002<\/li>\n<\/ul>\n<p><strong>let\u5173\u952e\u5b57<\/strong><\/p>\n<ul>\n<li>let\u5173\u952e\u5b57\u58f0\u660e\u7684\u662f<strong>\u5c40\u90e8\u53d8\u91cf<\/strong>\uff0c\u53ea\u80fd\u5728\u5185\u8bbf\u95ee\u3002<\/li>\n<li>\u4f7f\u7528let\u58f0\u660e\u7684\u53d8\u91cf\u5728\u53d8\u91cf<strong>\u5b9a\u4e49<\/strong>\u524d\u65e0\u6cd5\u8bbf\u95ee\uff08\u6682\u65f6\u6027\u6b7b\u533a\uff09\u3002<\/li>\n<li>let\u58f0\u660e\u7684\u53d8\u91cf\u4e0d\u5141\u8bb8\u91cd\u590d\u58f0\u660e\u3002<\/li>\n<\/ul>\n<p>\u56e0\u6b64\uff0cvar\u58f0\u660e\u7684\u5168\u5c40\u53d8\u91cf\u53ef\u4ee5\u5728\u7a0b\u5e8f\u7684\u4efb\u4f55\u5730\u65b9\u4fee\u6539\u548c\u91cd\u65b0\u8d4b\u503c\u3002\u800clet\u58f0\u660e\u7684\u5c40\u90e8\u53d8\u91cf\u53ea\u80fd\u5728\u5176\u4f5c\u7528\u57df\u5185\u4fee\u6539\u548c\u91cd\u65b0\u8d4b\u503c\uff0c\u800c\u4e14\u53d8\u91cf\u58f0\u660e\u524d\u65e0\u6cd5\u8bbf\u95ee\u5b83\u3002<\/p>\n<p>\u53e6\u5916\uff0cJavaScript\u4e2d\u8fd8\u6709\u4e00\u4e2aconst\u5173\u952e\u5b57\uff0c\u7528\u4e8e\u58f0\u660e\u5e38\u91cf\u3002const\u58f0\u660e\u7684\u53d8\u91cf<strong>\u4e0d\u80fd\u88ab\u91cd\u65b0\u8d4b\u503c\u6216\u4fee\u6539<\/strong>\u3002\u5b83\u4e0elet\u7c7b\u4f3c\uff0c\u4e5f\u58f0\u660e\u7684\u662f\u5c40\u90e8\u53d8\u91cf\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJS\u53d8\u91cf\u58f0\u660e\uff1avar\u4e0elet\u6709\u4f55\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>JS\u4e2d\u7684\u53d8\u91cf\u58f0\u660e\u5173\u952e\u5b57var\u4e0elet\u8be6\u89e3 \u5728JavaScript\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528var\u548clet\u5173\u952e\u5b57\u6765\u58f0\u660e\u548c\u5b9a\u4e49\u53d8\u91cf\u3002\u7136\u800c\uff0c\u5b83\u4eec\u4e4b\u95f4\u5b58\u5728\u7740\u5173\u952e\u3002 var\u5173\u952e\u5b57 var\u5173\u952e\u5b57\u58f0\u660e\u7684\u662f\u5168\u5c40\u53d8\u91cf\uff0c\u53ef\u4ee5\u5728\u7a0b\u5e8f\u7684\u4efb\u4f55\u5730\u65b9\u8bbf\u95ee\u3002 \u4f7f\u7528var\u58f0\u660e\u7684\u53d8\u91cf\u5728\u53d8\u91cf\u58f0\u660e\u524d\u4e5f\u53ef\u4ee5\u8bbf\u95ee\uff08\u58f0\u660e\u63d0\u5347\uff09\u3002 var\u58f0\u660e\u7684\u53d8\u91cf\u5141\u8bb8\u91cd\u590d\u58f0\u660e\uff0c\u4f46\u4f1a\u8986\u76d6\u4e4b\u524d\u7684\u58f0\u660e\u3002 let\u5173\u952e\u5b57 let\u5173\u952e\u5b57\u58f0\u660e\u7684\u662f\u5c40\u90e8\u53d8\u91cf\uff0c\u53ea\u80fd\u5728\u5185\u8bbf\u95ee\u3002 \u4f7f\u7528let\u58f0\u660e\u7684\u53d8\u91cf\u5728\u53d8\u91cf\u5b9a\u4e49\u524d\u65e0\u6cd5\u8bbf\u95ee\uff08\u6682\u65f6\u6027\u6b7b\u533a\uff09\u3002 let\u58f0\u660e\u7684\u53d8\u91cf\u4e0d\u5141\u8bb8\u91cd\u590d\u58f0\u660e\u3002 \u56e0\u6b64\uff0cvar\u58f0\u660e\u7684\u5168\u5c40\u53d8\u91cf\u53ef\u4ee5\u5728\u7a0b\u5e8f\u7684\u4efb\u4f55\u5730\u65b9\u4fee\u6539\u548c\u91cd\u65b0\u8d4b\u503c\u3002\u800clet\u58f0\u660e\u7684\u5c40\u90e8\u53d8\u91cf\u53ea\u80fd\u5728\u5176\u4f5c\u7528\u57df\u5185\u4fee\u6539\u548c\u91cd\u65b0\u8d4b\u503c\uff0c\u800c\u4e14\u53d8\u91cf\u58f0\u660e\u524d\u65e0\u6cd5\u8bbf\u95ee\u5b83\u3002 \u53e6\u5916\uff0cJavaScript\u4e2d\u8fd8\u6709\u4e00\u4e2aconst\u5173\u952e\u5b57\uff0c\u7528\u4e8e\u58f0\u660e\u5e38\u91cf\u3002const\u58f0\u660e\u7684\u53d8\u91cf\u4e0d\u80fd\u88ab\u91cd\u65b0\u8d4b\u503c\u6216\u4fee\u6539\u3002\u5b83\u4e0elet\u7c7b\u4f3c\uff0c\u4e5f\u58f0\u660e\u7684\u662f\u5c40\u90e8\u53d8\u91cf\u3002 \u4ee5\u4e0a\u5c31\u662fJS\u53d8\u91cf\u58f0\u660e\uff1avar\u4e0elet\u6709\u4f55\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-4082","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4082","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=4082"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4082\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=4082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=4082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=4082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}