{"id":2019,"date":"2025-02-25T22:26:28","date_gmt":"2025-02-25T14:26:28","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=2019"},"modified":"2025-02-25T22:26:28","modified_gmt":"2025-02-25T14:26:28","slug":"javascript-%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/02\/25\/javascript-%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/","title":{"rendered":"JavaScript \u6570\u636e\u7c7b\u578b"},"content":{"rendered":"\n<p>\u5728 JavaScript \u4e2d\uff0c\u6570\u636e\u7c7b\u578b\u7528\u4e8e\u6307\u5b9a\u53d8\u91cf\u53ef\u4ee5\u5b58\u50a8\u7684\u503c\u7684\u7c7b\u578b\u3002JavaScript \u652f\u6301\u4e24\u5927\u7c7b\u6570\u636e\u7c7b\u578b\uff1a<strong>\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff08\u539f\u59cb\u7c7b\u578b\uff09<\/strong>\u548c<strong>\u5f15\u7528\u6570\u636e\u7c7b\u578b<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u57fa\u672c\u6570\u636e\u7c7b\u578b<\/strong>\uff08Primitive Types\uff09<\/h3>\n\n\n\n<p>\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u503c\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u503c\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u80fd\u88ab\u4fee\u6539\u3002\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Number<\/strong>\uff1a\u6570\u5b57\u7c7b\u578b\uff0c\u8868\u793a\u6574\u6570\u6216\u6d6e\u52a8\u5c0f\u6570\u3002<\/li>\n\n\n\n<li><strong>String<\/strong>\uff1a\u5b57\u7b26\u4e32\u7c7b\u578b\uff0c\u8868\u793a\u6587\u672c\u6570\u636e\u3002<\/li>\n\n\n\n<li><strong>Boolean<\/strong>\uff1a\u5e03\u5c14\u7c7b\u578b\uff0c\u53ea\u6709\u4e24\u4e2a\u503c\uff1a<code>true<\/code> \u548c <code>false<\/code>\u3002<\/li>\n\n\n\n<li><strong>undefined<\/strong>\uff1a\u8868\u793a\u53d8\u91cf\u5df2\u58f0\u660e\u4f46\u672a\u8d4b\u503c\u3002<\/li>\n\n\n\n<li><strong>null<\/strong>\uff1a\u8868\u793a\u201c\u7a7a\u201d\u6216\u201c\u65e0\u503c\u201d\u7684\u7279\u6b8a\u5bf9\u8c61\u7c7b\u578b\u3002<\/li>\n\n\n\n<li><strong>Symbol<\/strong>\uff08ES6 \u5f15\u5165\uff09\uff1a\u8868\u793a\u552f\u4e00\u4e14\u4e0d\u53ef\u53d8\u7684\u503c\uff0c\u5e38\u7528\u4e8e\u5bf9\u8c61\u5c5e\u6027\u7684\u6807\u8bc6\u7b26\u3002<\/li>\n\n\n\n<li><strong>BigInt<\/strong>\uff08ES11 \u5f15\u5165\uff09\uff1a\u7528\u4e8e\u8868\u793a\u4efb\u610f\u7cbe\u5ea6\u7684\u5927\u6574\u6570\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>let num = 42;  \/\/ Number\nlet str = \"Hello, World!\";  \/\/ String\nlet isActive = true;  \/\/ Boolean\nlet nothing = undefined;  \/\/ Undefined\nlet emptyValue = null;  \/\/ Null\nlet uniqueSymbol = Symbol(\"id\");  \/\/ Symbol\nlet largeNumber = 1234567890123456789012345678901234567890n;  \/\/ BigInt<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u5f15\u7528\u6570\u636e\u7c7b\u578b<\/strong>\uff08Reference Types\uff09<\/h3>\n\n\n\n<p>\u5f15\u7528\u6570\u636e\u7c7b\u578b\u4e0e\u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e0d\u540c\uff0c\u5b83\u4eec\u7684\u503c\u662f\u53ef\u53d8\u7684\uff0c\u5e76\u4e14\u5b58\u50a8\u7684\u662f\u6307\u5411\u6570\u636e\u5b9e\u9645\u4f4d\u7f6e\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u6570\u636e\u672c\u8eab\u3002\u5f15\u7528\u6570\u636e\u7c7b\u578b\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Object<\/strong>\uff1a\u7528\u4e8e\u5b58\u50a8\u591a\u4e2a\u503c\u7684\u96c6\u5408\uff0c\u8fd9\u4e9b\u503c\u4ee5\u5c5e\u6027\u7684\u5f62\u5f0f\u5b58\u50a8\u3002<\/li>\n\n\n\n<li><strong>Array<\/strong>\uff1a\u7528\u4e8e\u5b58\u50a8\u6709\u5e8f\u7684\u503c\u7684\u96c6\u5408\uff0c\u6bcf\u4e2a\u503c\u53ef\u4ee5\u662f\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002<\/li>\n\n\n\n<li><strong>Function<\/strong>\uff1a\u7528\u4e8e\u5b9a\u4e49\u51fd\u6570\uff0c\u5b83\u4e5f\u662f\u4e00\u79cd\u5bf9\u8c61\u7c7b\u578b\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">a. <strong>Object<\/strong>\uff08\u5bf9\u8c61\uff09<\/h4>\n\n\n\n<p>\u5bf9\u8c61\u662f\u7531\u4e00\u7ec4\u952e\u503c\u5bf9\uff08\u5c5e\u6027\uff09\u6784\u6210\u7684\u96c6\u5408\u3002\u952e\uff08\u5c5e\u6027\u540d\uff09\u662f\u5b57\u7b26\u4e32\u7c7b\u578b\uff0c\u503c\u53ef\u4ee5\u662f\u4efb\u610f\u7c7b\u578b\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let person = {\n  name: \"Alice\",\n  age: 25,\n  isActive: true\n};\nconsole.log(person.name);  \/\/ \u8f93\u51fa\uff1aAlice<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">b. <strong>Array<\/strong>\uff08\u6570\u7ec4\uff09<\/h4>\n\n\n\n<p>\u6570\u7ec4\u662f\u5bf9\u8c61\u7684\u4e00\u79cd\u7279\u6b8a\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u6709\u5e8f\u7684\u6570\u636e\u96c6\u5408\u3002\u6570\u7ec4\u7684\u5143\u7d20\u53ef\u4ee5\u662f\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let colors = &#91;\"red\", \"green\", \"blue\"];\nconsole.log(colors&#91;0]);  \/\/ \u8f93\u51fa\uff1ared<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">c. <strong>Function<\/strong>\uff08\u51fd\u6570\uff09<\/h4>\n\n\n\n<p>\u51fd\u6570\u662f\u53ef\u4ee5\u6267\u884c\u4e00\u7ec4\u64cd\u4f5c\u7684\u4ee3\u7801\u5757\uff0c\u51fd\u6570\u4e5f\u662f\u4e00\u79cd\u5bf9\u8c61\u7c7b\u578b\uff0c\u53ef\u4ee5\u8d4b\u503c\u7ed9\u53d8\u91cf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function greet() {\n  console.log(\"Hello!\");\n}\ngreet();  \/\/ \u8f93\u51fa\uff1aHello!<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u7c7b\u578b\u8f6c\u6362\uff08Type Conversion\uff09<\/strong><\/h3>\n\n\n\n<p>JavaScript \u4f1a\u6839\u636e\u9700\u8981\u81ea\u52a8\u5c06\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7c7b\u578b\uff0c\u8fd9\u79f0\u4e3a<strong>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong>\uff0c\u4e5f\u53ef\u4ee5\u624b\u52a8\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">a. <strong>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong><\/h4>\n\n\n\n<p>JavaScript \u4f1a\u5728\u8868\u8fbe\u5f0f\u4e2d\u81ea\u52a8\u5c06\u4e0d\u540c\u7c7b\u578b\u7684\u503c\u8f6c\u6362\u4e3a\u5408\u9002\u7684\u7c7b\u578b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let num = 5 + \"10\";  \/\/ \u9690\u5f0f\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\nconsole.log(num);  \/\/ \u8f93\u51fa\uff1a\"510\"\n\nlet result = \"5\" - 2;  \/\/ \u9690\u5f0f\u8f6c\u6362\u4e3a\u6570\u5b57\nconsole.log(result);  \/\/ \u8f93\u51fa\uff1a3<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">b. <strong>\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong><\/h4>\n\n\n\n<p>\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684\u8f6c\u6362\u65b9\u6cd5\u624b\u52a8\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f6c\u6362\u4e3a\u6570\u5b57<\/strong>\uff1a\u4f7f\u7528 <code>Number()<\/code> \u6216 <code>parseInt()<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>let str = \"123\";\nlet num = Number(str);  \/\/ \u663e\u5f0f\u8f6c\u6362\u4e3a\u6570\u5b57\nconsole.log(num);  \/\/ \u8f93\u51fa\uff1a123<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<\/strong>\uff1a\u4f7f\u7528 <code>String()<\/code> \u6216 <code>toString()<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>let num = 123;\nlet str = String(num);  \/\/ \u663e\u5f0f\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\nconsole.log(str);  \/\/ \u8f93\u51fa\uff1a\"123\"<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c<\/strong>\uff1a\u4f7f\u7528 <code>Boolean()<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>let value = 0;\nlet bool = Boolean(value);  \/\/ \u663e\u5f0f\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c\nconsole.log(bool);  \/\/ \u8f93\u51fa\uff1afalse<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u68c0\u67e5\u6570\u636e\u7c7b\u578b<\/strong><\/h3>\n\n\n\n<p>\u53ef\u4ee5\u4f7f\u7528 <code>typeof<\/code> \u8fd0\u7b97\u7b26\u68c0\u67e5\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u503c\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 <code>Array.isArray()<\/code> \u6765\u68c0\u67e5\u6570\u7ec4\u7c7b\u578b\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>let x = 10;\nconsole.log(typeof x);  \/\/ \u8f93\u51fa\uff1a\"number\"\n\nlet str = \"Hello\";\nconsole.log(typeof str);  \/\/ \u8f93\u51fa\uff1a\"string\"\n\nlet obj = { name: \"Alice\" };\nconsole.log(typeof obj);  \/\/ \u8f93\u51fa\uff1a\"object\"\n\nlet arr = &#91;1, 2, 3];\nconsole.log(Array.isArray(arr));  \/\/ \u8f93\u51fa\uff1atrue<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u7279\u6b8a\u7c7b\u578b<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>NaN<\/strong>\uff08Not a Number\uff09\uff1a\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u6570\u5b57\u503c\uff0c\u8868\u793a\u4e00\u4e2a\u65e0\u6cd5\u8868\u793a\u7684\u6570\u503c\u3002<\/li>\n\n\n\n<li><strong>Infinity<\/strong>\uff1a\u8868\u793a\u65e0\u7a77\u5927\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>let x = 10 \/ 0;\nconsole.log(x);  \/\/ \u8f93\u51fa\uff1aInfinity\n\nlet y = \"Hello\" \/ 2;\nconsole.log(y);  \/\/ \u8f93\u51fa\uff1aNaN<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u5c0f\u7ed3<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u57fa\u672c\u6570\u636e\u7c7b\u578b<\/strong>\uff1a<code>Number<\/code>\u3001<code>String<\/code>\u3001<code>Boolean<\/code>\u3001<code>undefined<\/code>\u3001<code>null<\/code>\u3001<code>Symbol<\/code>\u3001<code>BigInt<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u5f15\u7528\u6570\u636e\u7c7b\u578b<\/strong>\uff1a<code>Object<\/code>\u3001<code>Array<\/code>\u3001<code>Function<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u7c7b\u578b\u8f6c\u6362<\/strong>\uff1aJavaScript \u53ef\u4ee5\u9690\u5f0f\u6216\u663e\u5f0f\u5730\u5c06\u503c\u8f6c\u6362\u4e3a\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002<\/li>\n\n\n\n<li><strong>\u68c0\u67e5\u7c7b\u578b<\/strong>\uff1a\u4f7f\u7528 <code>typeof<\/code> \u6216 <code>Array.isArray()<\/code> \u7b49\u65b9\u6cd5\u6765\u68c0\u67e5\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\u8bf7\u5173\u6ce8\u5176\u4ed6\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 JavaScript \u4e2d\uff0c\u6570\u636e\u7c7b\u578b\u7528\u4e8e\u6307\u5b9a\u53d8\u91cf\u53ef\u4ee5\u5b58\u50a8\u7684\u503c\u7684\u7c7b\u578b\u3002JavaScript \u652f\u6301\u4e24\u5927\u7c7b\u6570\u636e\u7c7b\u578b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[],"class_list":["post-2019","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2019","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=2019"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2019\/revisions"}],"predecessor-version":[{"id":2020,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2019\/revisions\/2020"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=2019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=2019"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=2019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}