{"id":2040,"date":"2024-11-10T09:01:07","date_gmt":"2024-11-10T01:01:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2040\/"},"modified":"2024-11-10T09:01:07","modified_gmt":"2024-11-10T01:01:07","slug":"%e4%ba%86%e8%a7%a3-javascript-%e4%b8%ad%e7%9a%84%e5%8f%98%e9%87%8f%e5%92%8c%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2040\/","title":{"rendered":"\u4e86\u89e3 JavaScript \u4e2d\u7684\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173063273721492.jpg\" class=\"aligncenter\" title=\"\u4e86\u89e3 JavaScript \u4e2d\u7684\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u63d2\u56fe\" alt=\"\u4e86\u89e3 JavaScript \u4e2d\u7684\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u63d2\u56fe\" \/><\/p>\n<p>javascript \u662f\u4e00\u79cd\u5e7f\u6cdb\u7528\u4e8e web \u5f00\u53d1\u7684\u52a8\u6001\u7f16\u7a0b\u8bed\u8a00\u3002 javascript \u7684\u57fa\u672c\u6982\u5ff5\u4e4b\u4e00\u662f\u7406\u89e3\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u3002\u672c\u6587\u5c06\u6e05\u695a\u5730\u89e3\u91ca\u8fd9\u4e9b\u6982\u5ff5\uff0c\u5e2e\u52a9\u60a8\u8f7b\u677e\u638c\u63e1\u5b83\u4eec\u3002<\/p>\n<p><strong>\u4ec0\u4e48\u662f\u53d8\u91cf\uff1f<\/strong><br \/> \u53d8\u91cf\u5c31\u50cf\u4fdd\u5b58\u6570\u636e\u503c\u7684\u5bb9\u5668\u3002\u5728 javascript \u4e2d\uff0c\u60a8\u53ef\u4ee5\u5728\u53d8\u91cf\u4e2d\u5b58\u50a8\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u8981\u58f0\u660e\u53d8\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528\u5173\u952e\u5b57 var\u3001let \u6216 const\u3002\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4e0b\uff1a<\/p>\n<h4> \u53d8\u91cf\uff1a <\/h4>\n<ul>\n<li>\u8fd9\u662f\u4e00\u79cd\u58f0\u660e\u53d8\u91cf\u7684\u65e7\u65b9\u6cd5\u3002<\/li>\n<li>var \u53d8\u91cf\u7684\u662f\u5168\u5c40\u7684\u6216\u51fd\u6570\u7ea7\u7684\u3002<\/li>\n<li>\u4f60\u53ef\u4ee5\u7528var\u91cd\u65b0\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\u3002 <\/li>\n<\/ul>\n<pre>var name = \"ali\";\nvar name = \"ahmed\"; \/\/ this is valid\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4> \u8ba9\uff1a <\/h4>\n<ul>\n<li>\u6b64\u5173\u952e\u5b57\u7528\u4e8e\u5757\u8303\u56f4\u53d8\u91cf\u3002<\/li>\n<li>\u4f60\u4e0d\u80fd\u91cd\u65b0\u58f0\u660e\u7528let\u58f0\u660e\u7684\u53d8\u91cf\u3002 <\/li>\n<\/ul>\n<pre>let age = 25;\n\/\/ let age = 30; \/\/ this will give an error\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4> \u5e38\u91cf\uff1a <\/h4>\n<ul>\n<li>\u4e5f\u662f\u5757\u4f5c\u7528\u57df\uff0c\u4f46\u5b83\u7528\u4e8e\u5e38\u91cf\u3002<\/li>\n<li>\u4f60\u4e0d\u80fd\u91cd\u65b0\u5206\u914d\u7528const\u58f0\u660e\u7684\u53d8\u91cf\uff0c\u4f46\u5982\u679c\u5b83\u662f\u4e00\u4e2a\u5bf9\u8c61\u6216\u6570\u7ec4\uff0c\u4f60\u53ef\u4ee5\u6539\u53d8\u5b83\u7684\u5c5e\u6027\u3002 <\/li>\n<\/ul>\n<pre>const pi = 3.14;\n\/\/ pi = 3.14159; \/\/ this will give an error\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u4ec0\u4e48\u662f\u6570\u636e\u7c7b\u578b\uff1f <\/h3>\n<p>javascript \u4e2d\u7684\u6570\u636e\u7c7b\u578b\u6307\u5b9a\u53d8\u91cf\u53ef\u4ee5\u4fdd\u5b58\u54ea\u79cd\u6570\u636e\u3002\u6570\u636e\u7c7b\u578b\u4e3b\u8981\u6709\u4e24\u5927\u7c7b\uff1a\u539f\u59cb\u7c7b\u578b\u548c\u975e\u539f\u59cb\u7c7b\u578b\u3002<\/p>\n<h4> \u539f\u59cb\u6570\u636e\u7c7b\u578b <\/h4>\n<p>\u539f\u59cb\u6570\u636e\u7c7b\u578b\u662f\u6700\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\u3002 javascript \u6709\u4e03\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li> <strong>\u5b57\u7b26\u4e32\uff1a<\/strong> \u8868\u793a\u5b57\u7b26\u5e8f\u5217\u3002\u5b57\u7b26\u4e32\u7528 &#8211; &#8211; \u5355\u5f15\u53f7\u6216\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u3002 <\/li>\n<\/ul>\n<pre>let greeting = \"hello, world!\";\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>number\uff1a<\/strong> \u8868\u793a\u6574\u6570\u548c\u6d6e\u70b9\u6570\u3002 <\/li>\n<\/ul>\n<pre>let count = 42; \/\/ integer\nlet price = 9.99; \/\/ floating-point number\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>\u5e03\u5c14\u503c\uff1a<\/strong> \u8868\u793a\u4e00\u4e2a\u503c\uff0c\u53ef\u4ee5\u662f true \u4e5f\u53ef\u4ee5\u662f false\u3002 <\/li>\n<\/ul>\n<pre>let isloggedin = true;\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>\u672a\u5b9a\u4e49\uff1a<\/strong> \u8868\u793a\u53d8\u91cf\u5df2\u88ab\u58f0\u660e\u4f46\u5c1a\u672a\u8d4b\u503c\u3002 <\/li>\n<\/ul>\n<pre>let result; \/\/ this is undefined\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>null\uff1a<\/strong> \u8868\u793a\u6545\u610f\u7684\u975e\u503c\u6216\u7a7a\u503c\u3002 <\/li>\n<\/ul>\n<pre>let user = null; \/\/ this means there is no user\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>\u7b26\u53f7\uff08es6\u4e2d\u5f15\u5165\uff09\uff1a<\/strong>\u8868\u793a\u552f\u4e00\u4e14\u4e0d\u53ef\u53d8\u7684\u503c\uff0c\u4e3b\u8981\u7528\u4f5c\u5bf9\u8c61\u5c5e\u6027\u3002 <\/li>\n<\/ul>\n<pre>const uniqueid = symbol('id');\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>bigint\uff08\u5728 es11 \u4e2d\u5f15\u5165\uff09\uff1a<\/strong> \u7528\u4e8e\u8868\u793a\u4efb\u610f\u7cbe\u5ea6\u7684\u6574\u6570\uff0c\u5bf9\u4e8e\u975e\u5e38\u5927\u7684\u6570\u5b57\u5f88\u6709\u7528\u3002 <\/li>\n<\/ul>\n<pre>const bignumber = bigint(123456789012345678901234567890);\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4> \u975e\u539f\u59cb\u6570\u636e\u7c7b\u578b <\/h4>\n<p>\u975e\u539f\u59cb\u6570\u636e\u7c7b\u578b\u66f4\u590d\u6742\uff0c\u53ef\u4ee5\u4fdd\u5b58\u503c\u7684\u96c6\u5408\u6216\u66f4\u590d\u6742\u7684\u5b9e\u4f53\u3002\u6700\u5e38\u89c1\u7684\u975e\u539f\u59cb\u6570\u636e\u7c7b\u578b\u662f\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li> <strong>object\uff1a<\/strong> \u8868\u793a\u7684\u96c6\u5408\u3002\u5bf9\u8c61\u53ef\u4ee5\u4fdd\u5b58\u591a\u4e2a\u503c\uff0c\u5bf9\u4e8e\u7ba1\u7406\u66f4\u590d\u6742\u7684\u6570\u636e\u81f3\u5173\u91cd\u8981\u3002 <\/li>\n<\/ul>\n<pre>let person = {\n    name: \"Ali\",\n    age: 30,\n    isStudent: false\n};\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4> \u6982\u62ec <\/h4>\n<p>\u5728 javascript \u4e2d\uff0c\u53d8\u91cf\u662f\u5b58\u50a8\u6570\u636e\u503c\u7684\u5bb9\u5668\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 var\u3001let \u6216 const \u6765\u58f0\u660e\u5b83\u4eec\u3002\u6570\u636e\u7c7b\u578b\u4e3b\u8981\u6709\u4e24\u5927\u7c7b\uff1a\u539f\u59cb\u6570\u636e\u7c7b\u578b\u548c\u975e\u539f\u59cb\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<ul>\n<li>\n<p>\u539f\u59cb\u6570\u636e\u7c7b\u578b\uff1a\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u5e03\u5c14\u503c\u3001\u672a\u5b9a\u4e49\u3001null\u3001\u7b26\u53f7\u548c bigint\u3002<\/p>\n<\/li>\n<li>\n<p>\u975e\u539f\u59cb\u6570\u636e\u7c7b\u578b\uff1a\u5bf9\u8c61\u3002<br \/> \u7406\u89e3\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u4eec\u6784\u6210\u4e86 javascript \u7f16\u7a0b\u7684\u57fa\u7840\u3002\u4e00\u65e6\u638c\u63e1\u4e86\u8fd9\u4e9b\u6982\u5ff5\uff0c\u60a8\u5c31\u53ef\u4ee5\u6709\u6548\u5730\u7f16\u5199\u66f4\u590d\u6742\u7684\u7a0b\u5e8f\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5982\u679c\u60a8\u5bf9\u8fd9\u4e9b\u4e3b\u9898\u6709\u4efb\u4f55\u7591\u95ee\u6216\u9700\u8981\u8fdb\u4e00\u6b65\u89e3\u91ca\uff0c\u8bf7\u968f\u65f6\u8054\u7cfb\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e86\u89e3 JavaScript \u4e2d\u7684\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\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>javascript \u662f\u4e00\u79cd\u5e7f\u6cdb\u7528\u4e8e web \u5f00\u53d1\u7684\u52a8\u6001\u7f16\u7a0b\u8bed\u8a00\u3002 javascript \u7684\u57fa\u672c\u6982\u5ff5\u4e4b\u4e00\u662f\u7406\u89e3\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u3002\u672c\u6587\u5c06\u6e05\u695a\u5730\u89e3\u91ca\u8fd9\u4e9b\u6982\u5ff5\uff0c\u5e2e\u52a9\u60a8\u8f7b\u677e\u638c\u63e1\u5b83\u4eec\u3002 \u4ec0\u4e48\u662f\u53d8\u91cf\uff1f \u53d8\u91cf\u5c31\u50cf\u4fdd\u5b58\u6570\u636e\u503c\u7684\u5bb9\u5668\u3002\u5728 javascript \u4e2d\uff0c\u60a8\u53ef\u4ee5\u5728\u53d8\u91cf\u4e2d\u5b58\u50a8\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u8981\u58f0\u660e\u53d8\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528\u5173\u952e\u5b57 var\u3001let \u6216 const\u3002\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4e0b\uff1a \u53d8\u91cf\uff1a \u8fd9\u662f\u4e00\u79cd\u58f0\u660e\u53d8\u91cf\u7684\u65e7\u65b9\u6cd5\u3002 var \u53d8\u91cf\u7684\u662f\u5168\u5c40\u7684\u6216\u51fd\u6570\u7ea7\u7684\u3002 \u4f60\u53ef\u4ee5\u7528var\u91cd\u65b0\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\u3002 var name = &#8220;ali&#8221;; var name = &#8220;ahmed&#8221;; \/\/ this is valid \u767b\u5f55\u540e\u590d\u5236 \u8ba9\uff1a \u6b64\u5173\u952e\u5b57\u7528\u4e8e\u5757\u8303\u56f4\u53d8\u91cf\u3002 \u4f60\u4e0d\u80fd\u91cd\u65b0\u58f0\u660e\u7528let\u58f0\u660e\u7684\u53d8\u91cf\u3002 let age = 25; \/\/ let age = 30; \/\/ this will give an error \u767b\u5f55\u540e\u590d\u5236 \u5e38\u91cf\uff1a \u4e5f\u662f\u5757\u4f5c\u7528\u57df\uff0c\u4f46\u5b83\u7528\u4e8e\u5e38\u91cf\u3002 \u4f60\u4e0d\u80fd\u91cd\u65b0\u5206\u914d\u7528const\u58f0\u660e\u7684\u53d8\u91cf\uff0c\u4f46\u5982\u679c\u5b83\u662f\u4e00\u4e2a\u5bf9\u8c61\u6216\u6570\u7ec4\uff0c\u4f60\u53ef\u4ee5\u6539\u53d8\u5b83\u7684\u5c5e\u6027\u3002 const pi [&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-2040","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2040","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=2040"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2040\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}