{"id":2050,"date":"2025-02-25T23:18:03","date_gmt":"2025-02-25T15:18:03","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=2050"},"modified":"2025-02-25T23:18:03","modified_gmt":"2025-02-25T15:18:03","slug":"javascript-%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/02\/25\/javascript-%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2\/","title":{"rendered":"JavaScript\u00a0\u7c7b\u578b\u8f6c\u6362"},"content":{"rendered":"\n<p>\u5728 JavaScript \u4e2d\uff0c\u7c7b\u578b\u8f6c\u6362\u662f\u6307\u5c06\u4e00\u4e2a\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u53e6\u4e00\u4e2a\u6570\u636e\u7c7b\u578b\u7684\u8fc7\u7a0b\u3002JavaScript \u4e2d\u7684\u7c7b\u578b\u8f6c\u6362\u5206\u4e3a\u4e24\u79cd\u7c7b\u578b\uff1a<strong>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong>\uff08\u81ea\u52a8\u8f6c\u6362\uff09\u548c <strong>\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong>\uff08\u624b\u52a8\u8f6c\u6362\uff09\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. \u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong><\/h3>\n\n\n\n<p>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\uff0c\u4e5f\u79f0\u4e3a<strong>\u81ea\u52a8\u7c7b\u578b\u8f6c\u6362<\/strong>\uff0c\u662f\u6307 JavaScript \u81ea\u52a8\u5c06\u67d0\u4e2a\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u5176\u4ed6\u7c7b\u578b\u3002\u8fd9\u901a\u5e38\u53d1\u751f\u5728\u8fd0\u7b97\u7b26\u4f7f\u7528\u6216\u6bd4\u8f83\u65f6\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u793a\u4f8b\uff1a\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6570\u5b57\u4e0e\u5b57\u7b26\u4e32\u7684\u52a0\u6cd5\u8fd0\u7b97<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>let result = 5 + \"5\";\nconsole.log(result);  \/\/ \u8f93\u51fa \"55\"\uff08\u5b57\u7b26\u4e32\u62fc\u63a5\uff09<\/code><\/pre>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>5<\/code> \u662f\u4e00\u4e2a\u6570\u5b57\uff0c<code>\"5\"<\/code> \u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002JavaScript \u81ea\u52a8\u5c06\u6570\u5b57 <code>5<\/code> \u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32 <code>\"5\"<\/code>\uff0c\u7136\u540e\u8fdb\u884c\u5b57\u7b26\u4e32\u62fc\u63a5\u3002<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u6570\u5b57\u4e0e\u5b57\u7b26\u4e32\u7684\u51cf\u6cd5\u8fd0\u7b97<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>let result = 5 - \"3\";\nconsole.log(result);  \/\/ \u8f93\u51fa 2\uff08\u6570\u5b57\u8fd0\u7b97\uff09<\/code><\/pre>\n\n\n\n<p>\u5728\u8fd9\u91cc\uff0cJavaScript \u81ea\u52a8\u5c06\u5b57\u7b26\u4e32 <code>\"3\"<\/code> \u8f6c\u6362\u4e3a\u6570\u5b57 <code>3<\/code>\uff0c\u7136\u540e\u8fdb\u884c\u51cf\u6cd5\u8fd0\u7b97\u3002<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u5e03\u5c14\u503c\u4e0e\u6570\u5b57\u7684\u8f6c\u6362<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>let result1 = true + 1;\nlet result2 = false + 1;\n\nconsole.log(result1);  \/\/ \u8f93\u51fa 2\nconsole.log(result2);  \/\/ \u8f93\u51fa 1<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>true<\/code> \u88ab\u8f6c\u6362\u4e3a\u6570\u5b57 <code>1<\/code>\uff0c<code>false<\/code> \u88ab\u8f6c\u6362\u4e3a\u6570\u5b57 <code>0<\/code>\u3002<\/li>\n\n\n\n<li>\u5728\u52a0\u6cd5\u8fd0\u7b97\u4e2d\uff0c<code>true + 1<\/code> \u7684\u7ed3\u679c\u662f <code>2<\/code>\uff0c<code>false + 1<\/code> \u7684\u7ed3\u679c\u662f <code>1<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. \u663e\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong><\/h3>\n\n\n\n<p>\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362\uff0c\u4e5f\u53eb<strong>\u624b\u52a8\u7c7b\u578b\u8f6c\u6362<\/strong>\uff0c\u662f\u6307\u5f00\u53d1\u8005\u4f7f\u7528 JavaScript \u63d0\u4f9b\u7684\u51fd\u6570\u6216\u65b9\u6cd5\u6765\u8f6c\u6362\u53d8\u91cf\u7684\u7c7b\u578b\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u5e38\u89c1\u7684\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong><\/h4>\n\n\n\n<p>    1\u3001<strong>\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57<\/strong>\uff1a\u4f7f\u7528 <code>Number()<\/code> \u6216 <code>parseInt()<\/code>\u3001<code>parseFloat()<\/code> \u65b9\u6cd5\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\"><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>let str1 = \"123\";\nlet str2 = \"123.45\";\nlet str3 = \"abc\";\n\nlet num1 = Number(str1);\nlet num2 = parseInt(str2);\nlet num3 = parseFloat(str2);\nlet num4 = Number(str3);\n\nconsole.log(num1);  \/\/ \u8f93\u51fa 123\nconsole.log(num2);  \/\/ \u8f93\u51fa 123\nconsole.log(num3);  \/\/ \u8f93\u51fa 123.45\nconsole.log(num4);  \/\/ \u8f93\u51fa NaN<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Number()<\/code> \u5c1d\u8bd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\uff0c\u65e0\u6cd5\u8f6c\u6362\u65f6\u8fd4\u56de <code>NaN<\/code>\u3002<\/li>\n\n\n\n<li><code>parseInt()<\/code> \u4f1a\u89e3\u6790\u6574\u6570\u90e8\u5206\u3002<\/li>\n\n\n\n<li><code>parseFloat()<\/code> \u4f1a\u89e3\u6790\u6d6e\u52a8\u5c0f\u6570\u90e8\u5206\u3002<\/li>\n<\/ul>\n\n\n\n<p>    2\u3001<strong>\u6570\u5b57\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<\/strong>\uff1a\u4f7f\u7528 <code>String()<\/code> \u65b9\u6cd5\u6216 <code>.toString()<\/code> \u65b9\u6cd5\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\"><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>let num1 = 123;\nlet num2 = 456.78;\n\nlet str1 = String(num1);\nlet str2 = num2.toString();\n\nconsole.log(str1);  \/\/ \u8f93\u51fa \"123\"\nconsole.log(str2);  \/\/ \u8f93\u51fa \"456.78\"<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>String()<\/code> \u5c06\u6570\u5b57\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/li>\n\n\n\n<li><code>.toString()<\/code> \u65b9\u6cd5\u4e5f\u53ef\u4ee5\u5c06\u6570\u5b57\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n\n\n\n<p>    3\u3001<strong>\u5e03\u5c14\u503c\u8f6c\u6362<\/strong>\uff1a\u4f7f\u7528 <code>Boolean()<\/code> \u65b9\u6cd5\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\"><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>let str = \"hello\";\nlet num = 0;\n\nlet bool1 = Boolean(str);  \/\/ \u8f93\u51fa true\nlet bool2 = Boolean(num);  \/\/ \u8f93\u51fa false<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Boolean()<\/code> \u5c06\u4e00\u4e2a\u503c\u8f6c\u6362\u4e3a\u5e03\u5c14\u7c7b\u578b\u3002\u4efb\u4f55\u975e\u96f6\u6570\u5b57\u3001\u975e\u7a7a\u5b57\u7b26\u4e32\u548c\u5bf9\u8c61\u90fd\u4f1a\u8f6c\u6362\u4e3a <code>true<\/code>\uff0c<code>0<\/code>\u3001<code>null<\/code>\u3001<code>undefined<\/code> \u548c\u7a7a\u5b57\u7b26\u4e32\u4f1a\u8f6c\u6362\u4e3a <code>false<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. \u7c7b\u578b\u8f6c\u6362\u7684\u89c4\u5219<\/strong><\/h3>\n\n\n\n<p>JavaScript \u5bf9\u4e0d\u540c\u7c7b\u578b\u7684\u8f6c\u6362\u6709\u4e00\u4e9b\u89c4\u5219\uff0c\u8fd9\u4e9b\u89c4\u5219\u51b3\u5b9a\u4e86\u9690\u5f0f\u8f6c\u6362\u548c\u663e\u5f0f\u8f6c\u6362\u7684\u884c\u4e3a\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u52a0\u6cd5\u8fd0\u7b97\u7b26\uff08<code>+<\/code>\uff09<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\u53c2\u4e0e\u8fd0\u7b97\uff0cJavaScript \u4f1a\u5c06\u5176\u4ed6\u64cd\u4f5c\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u8fdb\u884c\u5b57\u7b26\u4e32\u62fc\u63a5\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   let result = \"Hello\" + 10;  \/\/ \u8f93\u51fa \"Hello10\"<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u51cf\u6cd5\u8fd0\u7b97\u7b26\uff08<code>-<\/code>\uff09<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u6709\u4e00\u4e2a\u975e\u6570\u5b57\u7c7b\u578b\uff0cJavaScript \u4f1a\u5c1d\u8bd5\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u5b57\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   let result = \"10\" - 5;  \/\/ \u8f93\u51fa 5<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08<code>==<\/code> \u548c <code>===<\/code>\uff09<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>==<\/code> \u4f1a\u5c1d\u8bd5\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u540e\u6bd4\u8f83\u503c\u662f\u5426\u76f8\u7b49\uff0c\u800c <code>===<\/code> \u4f1a\u6bd4\u8f83\u7c7b\u578b\u548c\u503c\uff0c\u4e14\u4e0d\u4f1a\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   console.log(5 == \"5\");   \/\/ \u8f93\u51fa true\n   console.log(5 === \"5\");  \/\/ \u8f93\u51fa false<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>\u8f6c\u6362 <code>null<\/code> \u548c <code>undefined<\/code><\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>null<\/code> \u8f6c\u6362\u4e3a <code>0<\/code>\uff08\u9664\u4e86\u52a0\u6cd5\u8fd0\u7b97\u7b26\uff0c\u5b83\u4f1a\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff09\u3002<\/li>\n\n\n\n<li><code>undefined<\/code> \u8f6c\u6362\u4e3a <code>NaN<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   console.log(Number(null));        \/\/ \u8f93\u51fa 0\n   console.log(Number(undefined));   \/\/ \u8f93\u51fa NaN<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. \u603b\u7ed3<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong>\uff1aJavaScript \u81ea\u52a8\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u901a\u5e38\u53d1\u751f\u5728\u8fd0\u7b97\u7b26\u4f7f\u7528\u65f6\u3002<\/li>\n\n\n\n<li><strong>\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong>\uff1a\u5f00\u53d1\u8005\u624b\u52a8\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u5e38\u7528\u7684\u65b9\u6cd5\u6709 <code>Number()<\/code>\u3001<code>String()<\/code>\u3001<code>Boolean()<\/code> \u7b49\u3002<\/li>\n\n\n\n<li><strong>\u6ce8\u610f<\/strong>\uff1a\u7c7b\u578b\u8f6c\u6362\u53ef\u80fd\u5bfc\u81f4\u4e00\u4e9b\u610f\u60f3\u4e0d\u5230\u7684\u7ed3\u679c\uff0c\u5982 <code>null<\/code> \u8f6c\u6362\u4e3a <code>0<\/code>\u3001\u7a7a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a <code>false<\/code> \u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u7406\u89e3\u7c7b\u578b\u8f6c\u6362\u89c4\u5219\u6709\u52a9\u4e8e\u907f\u514d\u9519\u8bef\uff0c\u5e76\u80fd\u5199\u51fa\u66f4\u6e05\u6670\u7684\u4ee3\u7801\u3002\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\u7c7b\u578b\u8f6c\u6362\u662f\u6307\u5c06\u4e00\u4e2a\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u53e6\u4e00\u4e2a\u6570\u636e\u7c7b\u578b\u7684\u8fc7\u7a0b\u3002JavaScript \u4e2d\u7684 [&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-2050","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2050","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=2050"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2050\/revisions"}],"predecessor-version":[{"id":2051,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2050\/revisions\/2051"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=2050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=2050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=2050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}