{"id":347,"date":"2024-12-19T00:29:49","date_gmt":"2024-12-18T16:29:49","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=347"},"modified":"2024-12-19T00:29:49","modified_gmt":"2024-12-18T16:29:49","slug":"javascript-%e4%b8%ad%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2%ef%bc%9a%e9%9a%90%e5%bc%8f%e4%b8%8e%e6%98%be%e5%bc%8f%e5%bc%ba%e5%88%b6%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2024\/12\/19\/javascript-%e4%b8%ad%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2%ef%bc%9a%e9%9a%90%e5%bc%8f%e4%b8%8e%e6%98%be%e5%bc%8f%e5%bc%ba%e5%88%b6%e8%bd%ac%e6%8d%a2\/","title":{"rendered":"JavaScript \u4e2d\u7c7b\u578b\u8f6c\u6362\uff1a\u9690\u5f0f\u4e0e\u663e\u5f0f\u5f3a\u5236\u8f6c\u6362"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">JavaScript \u4e2d\u7684 <strong>\u7c7b\u578b\u8f6c\u6362<\/strong> \u662f\u6307\u5c06\u4e00\u4e2a\u503c\u4ece\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u7684\u8fc7\u7a0b\u3002JavaScript \u662f\u4e00\u79cd <strong>\u5f31\u7c7b\u578b\u8bed\u8a00<\/strong>\uff0c\u610f\u5473\u7740\u5b83\u5728\u64cd\u4f5c\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u65f6\u4f1a\u81ea\u52a8\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u8fd9\u901a\u5e38\u53d1\u751f\u5728\u4f60\u6ca1\u6709\u660e\u786e\u8981\u6c42\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9\u79cd\u60c5\u51b5\u79f0\u4e3a <strong>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong>\u3002\u800c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u5e0c\u671b\u624b\u52a8\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u8fd9\u79f0\u4e3a <strong>\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong>\u3002<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\uff08Implicit Type Conversion\uff09<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u901a\u5e38\u53d1\u751f\u5728 JavaScript \u81ea\u52a8\u5c06\u4e00\u79cd\u7c7b\u578b\u7684\u503c\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7c7b\u578b\u65f6\u3002\u8fd9\u79cd\u8f6c\u6362\u901a\u5e38\u662f\u7531\u64cd\u4f5c\u7b26\uff08\u5982 <code>+<\/code>\u3001<code>==<\/code> \u7b49\uff09\u5f15\u8d77\u7684\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5e38\u89c1\u7684\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u573a\u666f<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">1.1 <strong>\u5b57\u7b26\u4e32\u548c\u6570\u5b57\u7684\u76f8\u52a0\uff08\u52a0\u6cd5\u8fd0\u7b97\u7b26 <code>+<\/code>\uff09<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u4f7f\u7528\u52a0\u6cd5\u8fd0\u7b97\u7b26\u65f6\uff0cJavaScript \u4f1a\u5c1d\u8bd5\u5c06\u5176\u4ed6\u7c7b\u578b\u7684\u503c\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let result = 5 + '5';   \/\/ '55'\uff08\u6570\u5b57 5 \u88ab\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32 '5'\uff09\nconsole.log(result);     \/\/ \u8f93\u51fa: '55'<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6570\u5b57 + \u5b57\u7b26\u4e32<\/strong>\uff1a\u6570\u5b57\u4f1a\u88ab\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u8fdb\u884c\u62fc\u63a5\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>let result = '5' + 5;   \/\/ '55'\uff08\u5b57\u7b26\u4e32 '5' \u548c\u6570\u5b57 5 \u62fc\u63a5\uff09\nconsole.log(result);     \/\/ \u8f93\u51fa: '55'<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">1.2 <strong>\u52a0\u6cd5\u4e0e\u975e\u6570\u5b57\u7684\u8f6c\u6362\uff08\u7c7b\u578b\u5f3a\u5236\u8f6c\u6362\uff09<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u52a0\u6cd5\u8fd0\u7b97\u7b26\u4e2d\uff0c\u975e\u6570\u5b57\u7c7b\u578b\u4f1a\u88ab\u8f6c\u6362\u4e3a\u6570\u5b57\u8fdb\u884c\u76f8\u52a0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let result = '5' - 1;    \/\/ 4\uff08\u5b57\u7b26\u4e32 '5' \u88ab\u8f6c\u6362\u4e3a\u6570\u5b57 5\uff09\nconsole.log(result);      \/\/ \u8f93\u51fa: 4<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b57\u7b26\u4e32 &#8211; \u6570\u5b57<\/strong>\uff1a\u5b57\u7b26\u4e32\u4f1a\u88ab\u8f6c\u6362\u4e3a\u6570\u5b57\uff08\u5982\u679c\u53ef\u80fd\u7684\u8bdd\uff09\uff0c\u7136\u540e\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\u3002<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">1.3 <strong>\u5e03\u5c14\u503c\u7684\u7c7b\u578b\u8f6c\u6362<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e03\u5c14\u503c\u4e5f\u4f1a\u6839\u636e\u4e0a\u4e0b\u6587\u8fdb\u884c\u9690\u5f0f\u8f6c\u6362\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5e03\u5c14\u503c <code>false<\/code><\/strong> \u4f1a\u88ab\u8f6c\u6362\u4e3a <code>0<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u5e03\u5c14\u503c <code>true<\/code><\/strong> \u4f1a\u88ab\u8f6c\u6362\u4e3a <code>1<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>let result = 5 + false;    \/\/ 5\uff08false \u88ab\u8f6c\u6362\u4e3a 0\uff09\nconsole.log(result);       \/\/ \u8f93\u51fa: 5\n\nresult = 5 + true;         \/\/ 6\uff08true \u88ab\u8f6c\u6362\u4e3a 1\uff09\nconsole.log(result);       \/\/ \u8f93\u51fa: 6<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">1.4 <strong>\u6bd4\u8f83\u64cd\u4f5c\uff08<code>==<\/code> \u548c <code>===<\/code>\uff09<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4f7f\u7528\u76f8\u7b49\u8fd0\u7b97\u7b26\uff08<code>==<\/code>\uff09\u65f6\uff0cJavaScript \u4f1a\u5c1d\u8bd5\u5c06\u4e24\u4e2a\u503c\u8f6c\u6362\u4e3a\u76f8\u540c\u7684\u7c7b\u578b\u8fdb\u884c\u6bd4\u8f83\u3002\u6ce8\u610f\uff0c<code>==<\/code> \u8fd0\u7b97\u7b26\u4f1a\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u800c <code>===<\/code> \u5219\u4e0d\u4f1a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ `==` \u4f1a\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\nconsole.log(5 == '5');  \/\/ true\uff08\u5b57\u7b26\u4e32 '5' \u88ab\u8f6c\u6362\u4e3a\u6570\u5b57 5\uff09\n\n\/\/ `===` \u4e0d\u4f1a\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\nconsole.log(5 === '5'); \/\/ false\uff08\u6570\u5b57\u548c\u5b57\u7b26\u4e32\u7c7b\u578b\u4e0d\u540c\uff09<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">1.5 <strong>\u81ea\u52a8\u8f6c\u6362\u4e3a\u6570\u5b57<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u4e9b\u64cd\u4f5c\uff08\u5982\u52a0\u6cd5\u3001\u51cf\u6cd5\u3001\u9664\u6cd5\u3001\u4e58\u6cd5\uff09\u4f1a\u5c1d\u8bd5\u5c06\u975e\u6570\u5b57\u7c7b\u578b\u7684\u503c\u8f6c\u6362\u4e3a\u6570\u5b57\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let result = '5' * 2;     \/\/ 10\uff08\u5b57\u7b26\u4e32 '5' \u88ab\u8f6c\u6362\u4e3a\u6570\u5b57 5\uff09\nconsole.log(result);       \/\/ \u8f93\u51fa: 10\n\nresult = '10' \/ 2;         \/\/ 5\uff08\u5b57\u7b26\u4e32 '10' \u88ab\u8f6c\u6362\u4e3a\u6570\u5b57 10\uff09\nconsole.log(result);       \/\/ \u8f93\u51fa: 5<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u975e\u6570\u5b57\u5b57\u7b26\u4e32<\/strong>\uff1a\u5f53\u5b57\u7b26\u4e32\u4e0d\u5305\u542b\u6570\u5b57\u65f6\uff0cJavaScript \u4f1a\u5c06\u5176\u8f6c\u6362\u4e3a <code>NaN<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>let result = 'hello' * 2;  \/\/ NaN\uff08\u5b57\u7b26\u4e32 'hello' \u65e0\u6cd5\u8f6c\u6362\u4e3a\u6570\u5b57\uff09\nconsole.log(result);        \/\/ \u8f93\u51fa: NaN<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">1.6 <strong>\u81ea\u52a8\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e00\u4e9b\u6761\u4ef6\u5224\u65ad\u4e2d\uff0c\u975e\u5e03\u5c14\u503c\u4f1a\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c\u3002JavaScript \u8ba4\u4e3a\u4ee5\u4e0b\u503c\u662f <strong>\u201c\u5047\u503c\u201d<\/strong>\uff08\u4f1a\u8f6c\u6362\u4e3a <code>false<\/code>\uff09\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>false<\/code><\/li>\n\n\n\n<li><code>0<\/code><\/li>\n\n\n\n<li><code>NaN<\/code><\/li>\n\n\n\n<li><code>\"\"<\/code>\uff08\u7a7a\u5b57\u7b26\u4e32\uff09<\/li>\n\n\n\n<li><code>null<\/code><\/li>\n\n\n\n<li><code>undefined<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u4ed6\u503c\u90fd\u4f1a\u88ab\u8f6c\u6362\u4e3a <code>true<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (0) {\n    console.log(\"\u4e0d\u4f1a\u8f93\u51fa\");\n} else {\n    console.log(\"0 \u662f\u5047\u503c\");\n}\n\nif ('hello') {\n    console.log(\"\u5b57\u7b26\u4e32 'hello' \u662f\u771f\u503c\");\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362\uff08Explicit Type Conversion\uff09<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362\u662f\u6307\u5f00\u53d1\u8005\u4e3b\u52a8\u5c06\u4e00\u4e2a\u503c\u4ece\u4e00\u79cd\u7c7b\u578b\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7c7b\u578b\u3002\u8fd9\u901a\u5e38\u662f\u901a\u8fc7 JavaScript \u63d0\u4f9b\u7684\u5185\u7f6e\u65b9\u6cd5\u5b9e\u73b0\u7684\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.1 <strong>\u5b57\u7b26\u4e32\u8f6c\u6362\uff08<code>String()<\/code>\uff09<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>String()<\/code> \u51fd\u6570\u5c06\u5176\u4ed6\u7c7b\u578b\u7684\u503c\u663e\u5f0f\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let num = 123;\nlet str = String(num);    \/\/ '123'\uff08\u6570\u5b57\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff09\nconsole.log(str);         \/\/ \u8f93\u51fa: '123'<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>String()<\/code> \u53ef\u4ee5\u5c06\u51e0\u4e4e\u6240\u6709\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>let bool = true;\nconsole.log(String(bool));  \/\/ 'true'\n\nlet obj = { name: 'Alice' };\nconsole.log(String(obj));   \/\/ '&#91;object Object]'<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.2 <strong>\u6570\u5b57\u8f6c\u6362\uff08<code>Number()<\/code>\uff09<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 <code>Number()<\/code> \u51fd\u6570\u5c06\u5176\u4ed6\u7c7b\u578b\u7684\u503c\u8f6c\u6362\u4e3a\u6570\u5b57\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let str = '123';\nlet num = Number(str);  \/\/ 123\uff08\u5b57\u7b26\u4e32 '123' \u8f6c\u6362\u4e3a\u6570\u5b57\uff09\nconsole.log(num);       \/\/ \u8f93\u51fa: 123<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b57\u7b26\u4e32\u8f6c\u6570\u5b57<\/strong>\uff1a\u5982\u679c\u5b57\u7b26\u4e32\u65e0\u6cd5\u8f6c\u6362\u4e3a\u6709\u6548\u6570\u5b57\uff0c\u5219\u8fd4\u56de <code>NaN<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>let str = 'hello';\nlet num = Number(str);  \/\/ NaN\uff08'hello' \u65e0\u6cd5\u8f6c\u6362\u4e3a\u6570\u5b57\uff09\nconsole.log(num);       \/\/ \u8f93\u51fa: NaN<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.3 <strong>\u5e03\u5c14\u503c\u8f6c\u6362\uff08<code>Boolean()<\/code>\uff09<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Boolean()<\/code> \u51fd\u6570\u53ef\u4ee5\u5c06\u503c\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c\u3002\u6240\u6709\u503c\u90fd\u53ef\u4ee5\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c\uff0c\u9664\u975e\u5b83\u4eec\u662f\u201c\u5047\u503c\u201d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let str = 'hello';\nlet bool = Boolean(str);  \/\/ true\uff08\u975e\u7a7a\u5b57\u7b26\u4e32\u88ab\u8f6c\u6362\u4e3a true\uff09\nconsole.log(bool);         \/\/ \u8f93\u51fa: true<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5047\u503c\u5305\u62ec <code>false<\/code>\u3001<code>0<\/code>\u3001<code>NaN<\/code>\u3001<code>\"\"<\/code>\u3001<code>null<\/code> \u548c <code>undefined<\/code>\uff0c\u5176\u4ed6\u503c\u90fd\u4f1a\u8f6c\u6362\u4e3a <code>true<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log(Boolean(0));         \/\/ false\nconsole.log(Boolean('hello'));   \/\/ true\nconsole.log(Boolean(null));      \/\/ false\nconsole.log(Boolean({}));        \/\/ true<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.4 <strong>\u5bf9\u8c61\u8f6c\u6362\uff08<code>Object()<\/code>\uff09<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>Object()<\/code> \u51fd\u6570\u5c06\u5176\u4ed6\u7c7b\u578b\u7684\u503c\u8f6c\u6362\u4e3a\u5bf9\u8c61\u3002\u901a\u5e38\uff0c\u5f53\u503c\u662f\u539f\u59cb\u7c7b\u578b\uff08\u5982\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u3001\u5e03\u5c14\u503c\uff09\u65f6\uff0cJavaScript \u4f1a\u5c06\u5176\u5305\u88c5\u6210\u5bf9\u5e94\u7684\u5bf9\u8c61\u7c7b\u578b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let str = 'hello';\nlet obj = Object(str);  \/\/ \u5b57\u7b26\u4e32 'hello' \u88ab\u5305\u88c5\u4e3a String \u5bf9\u8c61\nconsole.log(obj);        \/\/ \u8f93\u51fa: &#91;String: 'hello']<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.5 <strong>\u6570\u7ec4\u8f6c\u6362\uff08<code>Array()<\/code>\uff09<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u5c06\u5bf9\u8c61\u6216\u5176\u4ed6\u7c7b\u578b\u7684\u503c\u8f6c\u6362\u4e3a\u6570\u7ec4\uff0c\u5e38\u89c1\u7684\u65b9\u5f0f\u662f\u5c06 <code>arguments<\/code> \u6216\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let num = 123;\nlet arr = Array(num);  \/\/ \u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a 123 \u7684\u7a7a\u6570\u7ec4\nconsole.log(arr.length); \/\/ \u8f93\u51fa: 123<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u7c7b\u578b\u8f6c\u6362\u7684\u7ec6\u8282\u4e0e\u9677\u9631<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>NaN<\/code><\/strong>\uff1a<code>NaN<\/code> \u662f JavaScript \u4e2d\u7684\u4e00\u4e2a\u7279\u6b8a\u503c\uff0c\u8868\u793a\u201c\u4e0d\u662f\u4e00\u4e2a\u6570\u5b57\u201d\u3002\u5b83\u4e0d\u662f\u4efb\u4f55\u503c\u7684\u76f8\u7b49\u503c\uff0c\u5305\u62ec\u5b83\u672c\u8eab\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  console.log(NaN === NaN);  \/\/ false\n  console.log(Number('hello'));  \/\/ NaN<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7a7a\u5b57\u7b26\u4e32\u4e0e\u6570\u503c<\/strong>\uff1a<code>\"\"<\/code>\uff08\u7a7a\u5b57\u7b26\u4e32\uff09\u8f6c\u6362\u4e3a\u6570\u5b57\u65f6\u662f <code>0<\/code>\uff0c\u800c\u4f5c\u4e3a\u5e03\u5c14\u503c\u65f6\u662f <code>false<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  console.log(Number(''));  \/\/ 0\n  console.log(Boolean('')); \/\/ false<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>undefined<\/code> \u4e0e <code>null<\/code><\/strong>\uff1a<code>undefined<\/code> \u8f6c\u6362\u4e3a\u6570\u5b57\u65f6\u662f <code>NaN<\/code>\uff0c\u800c <code>null<\/code> \u8f6c\u6362\u4e3a\u6570\u5b57\u65f6\u662f <code>0<\/code>\u3002\u5b83\u4eec\u5728\u5e03\u5c14\u4e0a\u4e0b\u6587\u4e2d\u90fd\u88ab\u8f6c\u6362\u4e3a <code>false<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  console.log(Number(undefined));  \/\/ NaN\n  console.log(Number(null));       \/\/ 0\n  console.log(Boolean(undefined)); \/\/ false\n  console.log(Boolean(null));      \/\/ false<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u603b\u7ed3<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong>\uff1aJavaScript \u5728\u67d0\u4e9b\u64cd\u4f5c\u7b26\u7684\u4f7f\u7528\u4e2d\u81ea\u52a8\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u901a\u5e38\u4f60\u65e0\u9700\u663e\u5f0f\u8c03\u7528\u8f6c\u6362\u51fd\u6570\u3002\u5e38\u89c1\u7684\u64cd\u4f5c\u7b26\u5982 <code>+<\/code>\uff08\u52a0\u6cd5\uff09\uff0c<code>==<\/code>\uff08\u76f8\u7b49\u6bd4\u8f83\uff09\u7b49\u90fd\u4f1a\u89e6\u53d1\u9690\u5f0f\u8f6c\u6362\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362<\/strong>\uff1a\u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u7684\u8f6c\u6362\u51fd\u6570\u5982 <code>String()<\/code>\u3001<code>Number()<\/code>\u3001<code>Boolean()<\/code> \u7b49\u663e\u5f0f\u5730\u5c06\u503c\u8f6c\u6362\u4e3a\u76ee\u6807\u7c7b\u578b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5f3a\u5236\u8f6c\u6362<\/strong>\uff1a\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0cJavaScript \u4f1a\u5f3a\u5236\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u5982\u00a0<code>==<\/code>\u00a0\u6bd4\u8f83\u65f6\u4f1a\u8f6c\u6362\u7c7b\u578b\uff0c<code>+<\/code>\u00a0\u8fd0\u7b97\u7b26\u4f1a\u81ea\u52a8\u8f6c\u6362\u64cd\u4f5c\u6570\u7c7b\u578b\u7b49\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7406\u89e3\u8fd9\u4e9b\u7c7b\u578b\u8f6c\u6362\u89c4\u5219\u6709\u52a9\u4e8e\u5728 JavaScript \u4e2d\u907f\u514d\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u548c\u56f0\u60d1\uff0c\u7f16\u5199\u66f4\u7a33\u5065\u7684\u4ee3\u7801\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript \u4e2d\u7684 \u7c7b\u578b\u8f6c\u6362 \u662f\u6307\u5c06\u4e00\u4e2a\u503c\u4ece\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u7684\u8fc7\u7a0b\u3002JavaScrip [&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-347","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/347","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=347"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/347\/revisions"}],"predecessor-version":[{"id":348,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/347\/revisions\/348"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}