{"id":54,"date":"2024-04-17T10:45:33","date_gmt":"2024-04-17T10:45:33","guid":{"rendered":"http:\/\/icpnet.cn\/?p=54"},"modified":"2024-04-17T11:38:39","modified_gmt":"2024-04-17T11:38:39","slug":"javascript%e7%9a%84%e9%9a%90%e5%bc%8f%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"http:\/\/icpnet.cn\/?p=54","title":{"rendered":"JavaScript\u7684\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u8be6\u89e3"},"content":{"rendered":"\n<p><strong>JavaScript\u4e2d\u7684\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n\n\n\n<ul>\n<li>\u57fa\u7840\u6570\u636e\u7c7b\u578b\uff1aString,Number,Boolean,null,undefined,Symbol<\/li>\n\n\n\n<li>\u5f15\u7528\u6570\u636e\u7c7b\u578b\uff1aObject(Object,Array,Function\u90fd\u662fObject\u7c7b\u578b)<\/li>\n<\/ul>\n\n\n\n<p><strong>\u4ec0\u4e48\u662f\u9690\u5f0f\u8f6c\u6362<\/strong><\/p>\n\n\n\n<p>\u5f53\u8fd0\u7b97\u7b26\u5728\u8fd0\u7b97\u65f6\uff0c\u82e5\u4e24\u7aef\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u7edf\u4e00\uff0c\u7f16\u8bd1\u5668\u4f1a\u5e2e\u6211\u4eec\u81ea\u52a8\u8f6c\u6362\u6210\u76f8\u540c\u7c7b\u578b\u7684\u6570\u636e\uff0c\u8fd9\u5c31\u662f\u9690\u5f0f\u8f6c\u6362\u3002<\/p>\n\n\n\n<p><strong>\u9690\u5f0f\u8f6c\u6362\u89c4\u5219<\/strong><\/p>\n\n\n\n<p>\u9690\u5f0f\u8f6c\u6362\u662f\u4e00\u6b65\u4e00\u6b65\u5b8c\u6210\u7684\uff0c\u5982\u679c\u6bd4\u8f83\u6216\u8fd0\u7b97\u7684\u8fc7\u7a0b\u4e2d\u6570\u636e\u7c7b\u578b\u4ecd\u4e0d\u4e00\u81f4\uff0c\u6700\u7ec8\u4f1a\u5c06\u4e24\u8fb9\u6570\u636e\u90fd\u8f6c\u6210Number\u7c7b\u578b\u518d\u8fdb\u884c\u8fd0\u7b97\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"388\" src=\"http:\/\/icpnet.cn\/wp-content\/uploads\/2024\/04\/image-1-1024x388.png\" alt=\"\" class=\"wp-image-56\" srcset=\"http:\/\/icpnet.cn\/wp-content\/uploads\/2024\/04\/image-1-1024x388.png 1024w, http:\/\/icpnet.cn\/wp-content\/uploads\/2024\/04\/image-1-300x114.png 300w, http:\/\/icpnet.cn\/wp-content\/uploads\/2024\/04\/image-1-768x291.png 768w, http:\/\/icpnet.cn\/wp-content\/uploads\/2024\/04\/image-1.png 1514w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Object => String => Number<\/p>\n\n\n\n<p>Boolean => Number<\/p>\n\n\n\n<p>null\/undefined => Number<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f1a\u53d1\u751f\u9690\u5f0f\u8f6c\u6362<\/strong><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\">\u5f53\u8fd0\u7b97\u7b26\u4e24\u7aef\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u4e00\u81f4\uff0c\u4f1a\u89e6\u53d1\u9690\u5f0f\u8f6c\u6362<\/mark><\/p>\n\n\n\n<ol>\n<li><strong>+\u8fd0\u7b97\u7b26<\/strong><\/li>\n<\/ol>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\">+\u53ef\u4ee5\u62fc\u63a5\u5b57\u7b26\u4e32\uff0c\u4e5f\u662f\u8fd0\u7b97\u7b26<\/mark><\/p>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-primary-color\">Number\u53ea\u6709\u5f53\u4e0eNumber\u3001Boolean\u3001null\u3001undefined +\u65f6\u624d\u662f\u7b97\u672f\u8fd0\u7b97\u7b26<\/mark><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u62fc\u63a5\u5b57\u7b26\u4e32<\/strong><\/p>\n\n\n\n<p>\u975e\u5b57\u7b26\u4e32\u6570\u636e\u5148\u8c03\u7528String()\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u518d\u8fdb\u884c\u62fc\u63a5<\/p>\n\n\n\n<p>\u5bf9\u8c61\u7c7b\u578b\u5219toString()\u540e\u62fc\u63a5<\/p>\n\n\n\n<ul>\n<li>Number + String<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log(1+'\u6d4b\u8bd5') \/\/ \"1\u6d4b\u8bd5\"<\/code><\/pre>\n\n\n\n<ul>\n<li>Boolean + String<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log(true+'\u6d4b\u8bd5') \/\/ \"true\u6d4b\u8bd5\"<\/code><\/pre>\n\n\n\n<ul>\n<li>null + String     console.log(null+&#8217;\u6d4b\u8bd5&#8217;) \/\/ &#8220;null\u6d4b\u8bd5&#8221;<\/li>\n\n\n\n<li>undefined + String  console.log(undefined +&#8217;\u6d4b\u8bd5&#8217;) \/\/ &#8220;undefined \u6d4b\u8bd5&#8221;<\/li>\n\n\n\n<li>Array + String  console.log([1,2,3]+&#8217;\u6d4b\u8bd5&#8217;) \/\/ &#8220;1,2,3\u6d4b\u8bd5&#8221;<\/li>\n\n\n\n<li>Object+ String  console.log({}+&#8217;\u6d4b\u8bd5&#8217;) \/\/ &#8220;[object Object]\u6d4b\u8bd5&#8221;<\/li>\n\n\n\n<li>Function+ String<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>const fn = () => {\n  console.log(111)\n}\nconsole.log(fn+\"\u6d4b\u8bd5\");\n\/\/ () => {\n\/\/    console.log(111)\n\/\/ }\u6d4b\u8bd5<\/code><\/pre>\n\n\n\n<p>\u4e24\u4e2a\u975eString\u6570\u636e\u62fc\u63a5 \u5747\u53d8\u4e3aString \u518d\u8fdb\u884c\u62fc\u63a5<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u7b97\u672f\u8fd0\u7b97\u7b26<\/strong><\/p>\n\n\n\n<p>\u975eNumber\u6570\u636e\u5148\u8c03\u7528Number\uff08\uff09\u8f6c\u5316\u4e3a\u6570\u5b57\uff0c\u518d\u8fdb\u884c\u8fd0\u7b97<\/p>\n\n\n\n<ul>\n<li>Boolean\u4e2dtrue\u4e3a1\uff0cfalse\u4e3a0<\/li>\n\n\n\n<li>Null\u5f3a\u5236\u8f6c\u6362\u540e\u4e3a0<\/li>\n\n\n\n<li>undefined\u5f3a\u5236\u8f6c\u5316\u540e\u4e3aNaN<\/li>\n<\/ul>\n\n\n\n<p><strong>2. -\u8fd0\u7b97\u7b26<\/strong><\/p>\n\n\n\n<p>-\u8fd0\u7b97\u7b26\u53ea\u4f1a\u89c6\u4e3a\u8ba1\u7b97\uff0c\u6545\u4e0e\u5f15\u7528\u7c7b\u578b-\u65f6\uff0c\u53ea\u4f1a\u8fd4\u56deNaN<\/p>\n\n\n\n<p><strong>3.==\u8fd0\u7b97\u7b26<\/strong><\/p>\n\n\n\n<p>==\u53ea\u5224\u65ad\u503c\u662f\u5426\u76f8\u7b49<\/p>\n\n\n\n<p><strong>==\u4e24\u8fb9\u5747\u4e3a\u5f15\u7528\u6570\u636e\u7c7b\u578b\u65f6<\/strong><\/p>\n\n\n\n<p>\u8fd4\u56defalse\uff0c\u56e0\u4e3a\u5f15\u7528\u6570\u636e\u7c7b\u578b\u6bd4\u8f83\u7684\u662f\u5730\u5740<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u5f15\u7528\u7c7b\u578b\u6bd4\u8f83<\/strong><\/p>\n\n\n\n<p>\u53ea\u6709<code>\u957f\u5ea6\u5c0f\u4e8e1<\/code>\u7684<code>\u6570\u7ec4<\/code>\u624d<code>\u6709\u53ef\u80fd<\/code>\u8f6c\u4e3aNumber,\u957f\u5ea60\uff08\u7a7a\u6570\u7ec4\uff09 => \u201c\u201d => 0,[1] => \u201c1\u201d => 1<\/p>\n\n\n\n<p>\u800cFunction\u4e0eObject\u6700\u7ec8\u4e0d\u4f1a\u8f6c\u6210\u7eafNumber\u53ea\u80fd\u4e3aNaN<\/p>\n\n\n\n<ul>\n<li>\u4e0eBoolean\u6bd4\u8f83<\/li>\n<\/ul>\n\n\n\n<p>\u6839\u636e<code>\u9690\u5f0f\u8f6c\u6362\u89c4\u5219<\/code> Object => String => Number Boolean => Number \u4e8c\u8005\u6839\u636eNumber\u8fdb\u884c\u6bd4\u8f83<\/p>\n\n\n\n<ul>\n<li>\u4e0eString\u6bd4\u8f83<\/li>\n<\/ul>\n\n\n\n<p>Object => String \u6b64\u65f6\u4e0e\u5b57\u7b26\u4e32\u7c7b\u578b\u4e00\u81f4 \u4e0d\u5fc5\u7ee7\u7eed\u5c06\u4e8c\u8005\u8f6c\u4e3aNumber \u5c31\u53ef\u76f4\u63a5\u6bd4\u8f83<\/p>\n\n\n\n<ul>\n<li>\u4e0eNumber\u6bd4\u8f83<\/li>\n<\/ul>\n\n\n\n<p>Object => String => Number <strong>\u9700\u6ce8\u610f\uff1a<\/strong><code>\u6570\u7ec4\u957f\u5ea6<\/code>\u53ea\u8981<code>\u5927\u4e8e1<\/code>\uff0c\u6700\u7ec8\u7ed3\u679c\u5c31\u4e3a<code>NaN<\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6bd4\u8f83<\/strong><\/p>\n\n\n\n<p>\u5176\u4e2d<code>NaN<\/code>\u8f83\u4e3a\u7279\u6b8a\uff0cjs\u89c4\u5b9a\u5b83<code>\u4e0e\u4efb\u4f55\u6570\u636e\u6bd4\u8f83\u5747\u4e3afalse<\/code>\uff0c\u5305\u62ec\u5176\u672c\u8eab<\/p>\n\n\n\n<p>\u7279\u6b8a\u6848\u4f8b<\/p>\n\n\n\n<ul>\n<li>console.log(null == undefined) \/\/ true<\/li>\n\n\n\n<li>console.log(NaN ==NaN) \/\/ false<\/li>\n<\/ul>\n\n\n\n<p><strong>4.>\u6216\u8005&lt;\u8fd0\u7b97\u7b26<\/strong><\/p>\n\n\n\n<ul>\n<li>String \u4e0e Number  console.log(&#8217;11&#8217; > 10) \/\/true<\/li>\n\n\n\n<li>String \u4e2d\u7684\u5185\u5bb9\u4e3a<strong>\u5b57\u6bcd\u3001\u7b26\u53f7\u7b49\u7f16\u7801<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u82e5\u4e3a\u7b49\u957f\u5b57\u6bcd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log('a' > 'b') \/\/ false<\/code><\/pre>\n\n\n\n<p>\u82e5\u4e3a\u4e0d\u7b49\u957f\u5b57\u6bcd\uff0c\u6bd4\u8f83\u540c\u4f4d\u7f6e\u5b57\u6bcd\u5927\u5c0f\uff0c\u76f4\u81f3\u505a\u51fa\u5224\u65ad\u3002\u7b26\u5408\u540c\u7406\uff0c\u90fd\u662f\u6839\u636eACSII\u7801\u8fdb\u884c\u5224\u65ad<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log('ab' > 'b') \/\/ false\nconsole.log('abc' > 'abb') \/\/ true<\/code><\/pre>\n\n\n\n<p><strong>5.!\u53d6\u53cd<\/strong><\/p>\n\n\n\n<p><strong>\u6280\u5de7\uff1a<\/strong> \uff01\uff01\u8fde\u7eed\u4e24\u6b21\u53d6\u53cd\u53ef\u4ee5\u5c06\u975e\u5e03\u5c14\u503c\u8f6c\u6210\u5e03\u5c14\u503c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log(!!&#91;]) \/\/ true\nconsole.log(!&#91;]) \/\/ false\nconsole.log(!!{}) \/\/ true\nconsole.log(!!0) \/\/ false<\/code><\/pre>\n\n\n\n<p><strong>6. \u8bed\u53e5\u4e2d\u7684\u5224\u65ad\u6761\u4ef6\u4e5f\u4f1a\u89e6\u53d1\u9690\u5f0f\u8f6c\u6362<\/strong><\/p>\n\n\n\n<p>\u4f9d\u65e7\u6839\u636e\u9690\u5f0f\u8f6c\u6362\u89c4\u5219 \u6309\u5e8f\u8f6c\u6362<\/p>\n\n\n\n<ul>\n<li>false\u3001\u201c\u201d\u30010\u3001null\u3001undefined\u3001NaN \u88ab\u89c6\u4e3a false<\/li>\n\n\n\n<li>true\u30011 \u88ab\u89c6\u4e3a true<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u7c7b\u578b\u4e0d\u540c<\/p>\n\n\n\n<p>\u5982\u679c\u4e24\u8fb9\u7c7b\u578b\u4e0d\u540c\uff0c\u5219\u4e24\u8fb9\u90fd\u5c1d\u8bd5\u8f6c\u6210number\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u5f15\u7528\u7c7b\u578b\uff0c\u5148\u8c03\u7528valueOf()\uff0c\u5982\u679c\u80fd\u8f6c\u6210\u6570\u5b57\uff0c\u5219\u8fdb\u884c\u6bd4\u8f83\u3002<\/p>\n\n\n\n<p>\u4e0d\u80fd\u8f6c\u6210\u6570\u5b57\u5c31\u8c03\u7528toString()\u65b9\u6cd5\u8f6c\u6210\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u53c2\u8003\u94fe\u63a5<\/p>\n\n\n\n<ul>\n<li><a href=\"https:\/\/blog.csdn.net\/owo_ovo\/article\/details\/132090609\" data-type=\"link\" data-id=\"https:\/\/blog.csdn.net\/owo_ovo\/article\/details\/132090609\">\u3010JS\u3011JavaScript\u7684\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u8be6\u89e3<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript\u4e2d\u7684\u6570\u636e\u7c7b\u578b \u4ec0\u4e48\u662f\u9690\u5f0f\u8f6c\u6362 \u5f53\u8fd0\u7b97\u7b26\u5728\u8fd0\u7b97\u65f6\uff0c\u82e5\u4e24\u7aef\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u7edf\u4e00\uff0c\u7f16\u8bd1\u5668\u4f1a\u5e2e\u6211\u4eec\u81ea\u52a8\u8f6c\u6362\u6210\u76f8\u540c\u7c7b\u578b\u7684\u6570\u636e\uff0c\u8fd9\u5c31\u662f\u9690\u5f0f\u8f6c\u6362\u3002 \u9690\u5f0f\u8f6c\u6362\u89c4\u5219 \u9690\u5f0f\u8f6c\u6362\u662f\u4e00\u6b65\u4e00\u6b65\u5b8c\u6210\u7684\uff0c\u5982\u679c\u6bd4\u8f83\u6216\u8fd0\u7b97\u7684\u8fc7\u7a0b\u4e2d\u6570\u636e\u7c7b\u578b\u4ecd\u4e0d\u4e00\u81f4\uff0c\u6700\u7ec8\u4f1a\u5c06\u4e24\u8fb9\u6570\u636e\u90fd\u8f6c\u6210Number\u7c7b\u578b\u518d\u8fdb\u884c\u8fd0\u7b97\u3002 Object => String => Number Boolean => Number null\/undefined => Number \u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f1a\u53d1\u751f\u9690\u5f0f\u8f6c\u6362 \u5f53\u8fd0\u7b97\u7b26\u4e24\u7aef\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u4e00\u81f4\uff0c\u4f1a\u89e6\u53d1\u9690\u5f0f\u8f6c\u6362 +\u53ef\u4ee5\u62fc\u63a5\u5b57\u7b26\u4e32\uff0c\u4e5f\u662f\u8fd0\u7b97\u7b26 Number\u53ea\u6709\u5f53\u4e0eNumber\u3001Boolean\u3001null\u3001undefined +\u65f6\u624d\u662f\u7b97\u672f\u8fd0\u7b97\u7b26 \u62fc\u63a5\u5b57\u7b26\u4e32 \u975e\u5b57\u7b26\u4e32\u6570\u636e\u5148\u8c03\u7528String()\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u518d\u8fdb\u884c\u62fc\u63a5 \u5bf9\u8c61\u7c7b\u578b\u5219toString()\u540e\u62fc\u63a5 \u4e24\u4e2a\u975eString\u6570\u636e\u62fc\u63a5 \u5747\u53d8\u4e3aString \u518d\u8fdb\u884c\u62fc\u63a5 \u7b97\u672f\u8fd0\u7b97\u7b26 \u975eNumber\u6570\u636e\u5148\u8c03\u7528Number\uff08\uff09\u8f6c\u5316\u4e3a\u6570\u5b57\uff0c\u518d\u8fdb\u884c\u8fd0\u7b97 2. -\u8fd0\u7b97\u7b26 -\u8fd0\u7b97\u7b26\u53ea\u4f1a\u89c6\u4e3a\u8ba1\u7b97\uff0c\u6545\u4e0e\u5f15\u7528\u7c7b\u578b-\u65f6\uff0c\u53ea\u4f1a\u8fd4\u56deNaN 3.==\u8fd0\u7b97\u7b26 ==\u53ea\u5224\u65ad\u503c\u662f\u5426\u76f8\u7b49 ==\u4e24\u8fb9\u5747\u4e3a\u5f15\u7528\u6570\u636e\u7c7b\u578b\u65f6 \u8fd4\u56defalse\uff0c\u56e0\u4e3a\u5f15\u7528\u6570\u636e\u7c7b\u578b\u6bd4\u8f83\u7684\u662f\u5730\u5740 \u5f15\u7528\u7c7b\u578b\u6bd4\u8f83 \u53ea\u6709\u957f\u5ea6\u5c0f\u4e8e1\u7684\u6570\u7ec4\u624d\u6709\u53ef\u80fd\u8f6c\u4e3aNumber,\u957f\u5ea60\uff08\u7a7a\u6570\u7ec4\uff09 => \u201c\u201d => 0,[1] => \u201c1\u201d => 1 \u800cFunction\u4e0eObject\u6700\u7ec8\u4e0d\u4f1a\u8f6c\u6210\u7eafNumber\u53ea\u80fd\u4e3aNaN \u6839\u636e\u9690\u5f0f\u8f6c\u6362\u89c4\u5219 Object => String => Number Boolean => [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/icpnet.cn\/index.php?rest_route=\/wp\/v2\/posts\/54"}],"collection":[{"href":"http:\/\/icpnet.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/icpnet.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/icpnet.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/icpnet.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=54"}],"version-history":[{"count":3,"href":"http:\/\/icpnet.cn\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":60,"href":"http:\/\/icpnet.cn\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions\/60"}],"wp:attachment":[{"href":"http:\/\/icpnet.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/icpnet.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/icpnet.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}