{"id":3223,"date":"2013-05-07T18:02:14","date_gmt":"2013-05-07T10:02:14","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3223"},"modified":"2016-08-31T13:20:10","modified_gmt":"2016-08-31T05:20:10","slug":"%e7%90%86%e8%a7%a3another-javascript-quiz-%e9%a2%98%e7%9b%ae","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2013\/05\/%e7%90%86%e8%a7%a3another-javascript-quiz-%e9%a2%98%e7%9b%ae\/","title":{"rendered":"\u6211\u662f\u5982\u4f55\u7406\u89e3&#8221;Another JavaScript quiz&#8221;\u4e2d\u7684\u9898\u76ee"},"content":{"rendered":"<p>by <a href=\"http:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"http:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a><br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3223\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=3223<\/a><\/p>\n<style>.entry ol li{margin-top:1em; padding-bottom:1em;}<\/style>\n<h3>\u4e00\u3001\u4f60\u8fd9\u4e2a\u53d8\u6001\uff0c\u7ed9\u6211\u6eda\u5f00<\/h3>\n<p>\u65f6\u5149\u5189\u5189\uff0c\u6216\u591a\u6216\u5c11\u89c1\u8fc7\u4e00\u4e9bJavaScript\u76f8\u5173\u7684\u9898\u76ee\uff0c\u5176\u4e2d\u5f88\u591a\u5c5e\u4e8e\u53d8\u6001\u7ea7\u522b\u7684\uff01\u5404\u79cd\u5947\u602a\u7b26\u53f7\u5199\u6cd5\u62fc\u5728\u4e00\u8d77\u3001\u5c3c\u739b\u8fd8\u6709\u517c\u5bb9\u6027\u95ee\u9898\uff0c\u4f30\u8ba1\u9053\u683c\u62c9\u65af\u90fd\u4e0d\u77e5\u9053\u7b54\u6848\u3002<\/p>\n<p>\u5bf9\u4e8e\u8fd9\u79cd\u6574\u5f97\u4eb2\u5988\u90fd\u4e0d\u8ba4\u8bc6\u7684\u53d8\u6001\u95ee\u9898\uff0c\u5b9e\u9645\u4e0a\u662f\u6ca1\u6709\u4ec0\u4e48\u53c2\u8003\u4ef7\u503c\u7684\u3002\u597d\u6bd4\u8981\u8003\u5bdf\u5916\u661f\u4eba\u5bf9\u4eba\u7c7b\u7684\u4e86\u89e3\uff0c\u7ed3\u679c\u4f60\u90a3\u4e0b\u9762\u8fd9\u8d27\u6765\u505a\u6d4b\u8bd5\uff0c\u770b\u5230\u4eb2\u621a\u7684\u5916\u661f\u4eba\u4e00\u5b9a\u4f1a\u4e91\u91cc\u96fe\u91cc\u7684\uff0c\u4f46\u6709\u610f\u4e49\u5417\uff1f<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201305\/biantai.jpg\" width=\"180\" height=\"194\" alt=\"\u53d8\u6001\u4eba\u7c7b\" class=\"mt10\" \/><\/p>\n<p>\u597d\u7684JavaScript\u6d4b\u8bd5\u9898\u76ee\u5e94\u8be5\u662f\uff1a\u95e8\u5916\u6c49\u89c1\u4e86\u76b1\u7709\uff0c\u884c\u5bb6\u89c1\u4e86\u7591\u60d1\u9898\u76ee\u662f\u4e0d\u662f\u7b80\u5355\u4e86\u70b9\uff0c\u540c\u65f6\u8003\u5bdf\u70b9\u8986\u76d6\u5168\u9762\u3002<span class=\"s\">\/\/zxx: \u6211\u76ee\u524d\u8fd8\u6ca1\u6709\u8fd9\u4e2a\u80fd\u8010\u8bbe\u8ba1\u51fa\u5982\u6b64\u4f18\u79c0\u7684\u9898\u76ee\u3002<\/span><\/p>\n<p>\u8fd9\u91cc\u8981\u4ecb\u7ecd\u7684&#8221;<a href=\"http:\/\/james.padolsey.com\/javascript\/another-javascript-quiz\/\">Another JavaScript quiz<\/a>&#8220;(by james)\u4e2d\u7684\u9898\u76ee\u4e0d\u662f\u5c5e\u4e8e\u53d8\u6001\u9898\u76ee\uff0c\u800c\u662f\u786e\u5b9e\u5c5e\u4e8e\u53d8\u6001\u9898\u76ee\uff0c\u4e0d\u8fc7\u662f\u8868\u9762\u4e0a\u7684\uff0c\u5f88\u591a\u5185\u5bb9\u786e\u5b9e\u53ef\u80fd\u4f1a\u9047\u5230\u7684\u3002\u7efc\u5408\u8bc4\u4ef7\u4e0b\u5c31\u662f\uff1a\u9762\u8bd5\u4ef7\u503c\u4e0d\u53ca\u683c\uff0c\u5b66\u4e60\u4ef7\u503c\u662f\u5f88\u8d5e\u7684\uff0c\u56e0\u6b64\uff0c\u63a2\u8ba8\u5206\u4eab\u5f88\u6709\u610f\u4e49\u3002<\/p>\n<p>&#8220;<a href=\"http:\/\/james.padolsey.com\/javascript\/another-javascript-quiz\/\">Another JavaScript quiz<\/a>&#8220;\u4e2d\u670925\u4e2a\u5f88\u7b80\u6d01\u7684JavaScript\u6d4b\u8bd5\u9898\uff0c\u5168\u90e8\u90fd\u662f\u8003\u5bdf\u8fd4\u56de\u503c\u7684\uff0c\u4f8b\u5982<code>1 &amp;&amp; 3<\/code>\u7684\u8fd4\u56de\u503c\u662f\uff1f<\/p>\n<p>25\u9053\u9898\u76ee\u5168\u90e8\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u70b9\u51fb\u4e0b\u56fe\u6240\u793a\u7684\u6309\u94ae\uff0c\u68c0\u67e5\u4f60\u7684\u6b63\u786e\u7387\u4ee5\u53ca\u90a3\u4e9b\u9898\u76ee\u51fa\u9519\u4e86\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201305\/2013-05-02_174700.png\" width=\"485\" height=\"200\" alt=\"\u68c0\u67e5\u7b54\u6848\u6309\u94ae\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u6211\u81ea\u5df1\u5feb\u901f\u6d4b\u8bd5\u4e86\u4e0b\uff0c\u5982\u679c\u6bcf\u9898\u7b974\u5206\u7684\u8bdd\uff0c\u6211\u7684<a href=\"http:\/\/weibo.com\/1263362863\/ztn6GCI0Z\" title=\"\u5fae\u535a\u67e5\u770b\">\u6210\u7ee9\u662f56\u5206<\/a>\uff0c\u4e0d\u53ca\u683c\uff0c\u53ef\u89c1\u81ea\u5df1\u5bf9JS\u7684\u5b66\u4e60\u4ee5\u53ca\u7406\u89e3\u8fd8\u6709\u4e00\u6bb5\u8def\u8981\u8d70\u3002<\/p>\n<p>\u60a8\u4e5f\u53ef\u4ee5\u505a\u4e00\u4e0b\u8fd9\u4e9b\u9898\u76ee\uff0c\u5b8c\u6210\u4e4b\u540e\uff0c\u82e5\u6709\u7591\u60d1\uff0c\u53ef\u4ee5\u53c2\u8003\u6211\u4e0b\u9762\u7eaf\u4e2a\u4eba\u7684\u7406\u89e3 &#8211; \u90e8\u5206\u7406\u89e3\u53ef\u80fd\u4e0d\u51c6\u786e\uff0c\u6b22\u8fce\u6307\u6b63\u3002\u540c\u65f6\uff0c\u7f51\u4e0a\u5e94\u8be5\u6709\u5176\u4ed6\u4e00\u4e9b\u524d\u8f88\u7684\u89e3\u91ca\uff0c\u60a8\u4e5f\u53ef\u4ee5\u53c2\u8003\u53c2\u8003\u3002<\/p>\n<h3>\u4e8c\u3001\u516c\u5b50\uff0c\u4e0d\u6025\uff0c\u6162\u6162\u6765\u561b<\/h3>\n<ol>\n<li>\n<div class=\"zxx_code\">\n<pre>1 &amp;&amp; 3\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f<code>3<\/code>. <\/p>\n<p><code>&amp;&amp;<\/code>\u662f\u51e0\u4e4e\u65e0\u4eba\u4e0d\u77e5\uff0c\u8868\u793a\u201c\u4e0e\u201d\u3002\u7537\u65b9\u8981\u5a36\u6c34\u7075\u7075\u7684\u59b9\u5b50\uff0c\u4e03\u5927\u59d1\u516b\u5927\u5a46\u90fd\u8981\u540c\u610f\uff0c\u5426\u5219\u7ee7\u7eed\u953b\u70bc\u53f3\u624b\u5427\u3002<\/p>\n<p>\u4e0a\u9762<code>1 &amp;&amp; 3<\/code>\u672c\u8d28\u4e0a\u7b49\u540c\u4e8e<code>\u5927\u59d1\u5988 &amp;&amp; \u4e09\u59d1\u5988<\/code>\u3002<\/p>\n<p>\u4ece\u5de6\u5f80\u53f3\uff0c\u5982\u679c\u201c\u5927\u59d1\u5988\u201d\u901a\u8fc7\uff0c\u7ee7\u7eed\u201c\u4e09\u59d1\u5988\u201d\uff1b\u5426\u5219\u76f4\u63a5\u8fd4\u56de\u201c\u5927\u59d1\u5988\u201d\u3002\u56e0\u4e3a\u201c\u4e09\u59d1\u5988\u201d\u540e\u9762\u6ca1\u6709\u5176\u4ed6\u4eb2\u621a\u4e86\uff0c\u56e0\u6b64\u76f4\u63a5\u8fd4\u56de\u201c\u4e09\u59d1\u5988\u201d\u3002<\/p>\n<p>\u5728JavaScript\u4e2d\uff0c <code>1 == true \/\/ true<\/code>\uff0c\u56e0\u6b64\uff0c<code>1 &amp;&amp; 3<\/code>\u7b49\u540c\u4e8e\u201c\u5927\u59d1\u5988\u201d\u901a\u8fc7\u4e86\uff0c\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u68c0\u6d4b\u7684\u4eb2\u621a\u201c\u4e09\u59d1\u5988\u201d\uff0c\u4e5f\u5c31\u662f\u8fd9\u91cc\u7684\u7ed3\u679c<code>3<\/code>.<\/p>\n<p>\u56e0\u6b64\uff0c\u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u5e73\u65f6\u7684 <code>if (1 &amp;&amp; 3) {}<\/code> \u7b49\u540c\u4e8e <code>if (3) {}<\/code>.<\/p>\n<p>\u5982\u679c\u8fd9\u91cc\u7684\u9898\u76ee\u6362\u6210<code>0 &amp;&amp; 3<\/code>\u8fd4\u56de\u7684\u662f\uff1f\u90a3\u7ed3\u679c\u662f\u5982\u4f55\u5462\uff1f<\/p>\n<p>\u56e0\u4e3a<code>0 == false \/\/ true<\/code>, \u56e0\u6b64\u8d70\u4e0d\u5230\u201c\u4e09\u59d1\u5988\u201d\u8fd9\u4e00\u5173\uff0c\u76f4\u63a5\u8fd4\u56de\u4e86<code>0<\/code>. \u4e5f\u5c31\u662f<code>if (0 &amp;&amp; 3) {}<\/code> \u7b49\u540c\u4e8e <code>if (0) { <span style=\"color:#aaa;\">\/* \u4e0d\u4f1a\u6267\u884c *\/<\/span> }<\/code>.<\/p>\n<p><strong>\u5b9e\u7528\u6027<\/strong><br \/>\n\u53ef\u4ee5\u907f\u514d<code>if<\/code>\u5d4c\u5957\u3002\u4f8b\u5982\uff0c\u8981\u95ee\u9875\u9762\u4e0a\u67d0\u4e2adom\u7ed1\u5b9a\u70b9\u51fb\u4e8b\u4ef6\uff0c\u6211\u4eec\u9700\u8981\u5148\u5224\u65ad\u8fd9\u4e2adom\u5143\u7d20\u5b58\u4e0d\u5b58\u5728\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u8fd9\u6837\u505a\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>var dom = document.querySelector(\"#dom\");\nif (dom) { dom.addEventListener(\"click\", function() {});  }<\/pre>\n<\/div>\n<p>\u5b9e\u9645\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>&amp;&amp;<\/code>\u505a\u4e00\u4e9b\u7b80\u5316\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>var dom = document.querySelector(\"#dom\");\ndom && dom.addEventListener(\"click\", function() {});<\/pre>\n<\/div>\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>1 &amp;&amp; \"foo\" || 0\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u5f88\u7b80\u5355\u7684\u4e00\u9053\u9898\uff0c\u7ed3\u679c\u662f<code>\"foo\"<\/code>. <\/p>\n<p>\u8fd9\u91cc\u51fa\u73b0\u4e86\u4e00\u4e2a\u65b0\u7684\u5173\u7cfb\u7b26<code>||<\/code>, \u8868\u793a\u201c\u6216\u201d\u7684\u610f\u601d\u3002\u7537\u65b9\u8981\u5a36\u5e72\u5df4\u5df4\u7684\u59b9\u5b50\uff0c\u4e03\u5927\u59d1\u516b\u5927\u5a46\u53ea\u8981\u4e00\u4e2a\u8bf4\u597d\u5c31\u53ef\u4ee5\u4e86\u3002\u6bd4\u65b9\u8bf4<code>1 || 3<\/code>\u8868\u793a\uff1a\u5982\u679c\u5927\u59d1\u5988\u8bf4\u53ef\u4ee5\uff0c\u5219\u6210\u4e86\uff0c\u8fd4\u56de\u5927\u59d1\u5988\uff1b\u5982\u679c\u5927\u59d1\u5988\u4e0d\u5141\u8bb8\uff0c\u518d\u770b\u770b\u4e09\u59d1\u5988\u7684\u610f\u601d\u3002<\/p>\n<p>\u56e0\u6b64\uff0c<code>if (1 || 3) {}<\/code>\u5b9e\u9645\u7b49\u540c\u4e8e<code>if (1) {}<\/code>; <code>if (0 || 3) {}<\/code> \u7b49\u540c\u4e8e<code>if (3) {}<\/code>.<\/p>\n<p><strong>\u5b9e\u7528\u6027<\/strong><br \/>\n<code>||<\/code>\u53ef\u4ee5\u8ba9\u6211\u4eec\u4f7f\u7528\u4e00\u79cd\u66f4\u5feb\u6377\u7b80\u6613\u7684\u65b9\u5f0f\u4e3a\u53c2\u6570\u6dfb\u52a0\u9ed8\u8ba4\u503c\u3002\u4f8b\u5982\uff0c\u5199jQuery\u63d2\u4ef6\u7684\u65f6\u5019\uff0c\u53ef\u9009\u53c2\u6570\u662f\u53ef\u4ee5\u7f3a\u7701\u7684\uff0c\u6b64\u65f6\u5b9e\u9645\u4e0a\u503c\u4e3a<code>undefined<\/code>\uff0c\u4f1a\u8ba9\u540e\u9762\u7684\u53c2\u6570<code>extend<\/code>\u4ea7\u751f\u56f0\u6270\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u4f1a\u7ecf\u5e38\u89c1\u5230\u7c7b\u4f3c\u8fd9\u6837\u7684\u4ee3\u7801\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>$.fn.plugin = function(options) {\n    options = options || {};\n    <span style=\"color:graytext;\">\/\/ ...<\/span>\n};<\/pre>\n<\/div>\n<p>\u663e\u7136\uff0c\u6839\u636e\u4e0a\u9762\u7684\u7406\u89e3\uff0c<code>1 &amp;&amp; \"foo\"<\/code>\u8fd4\u56de\u7684\u662f<code>\"foo\"<\/code>, \u800c<code>\"foo\" || 0<\/code>, \u56e0<code>\"foo\" == true<\/code>\u4e3a<code>true<\/code>, \u81ea\u7136\u8fd4\u56de\u662f\u201c\u5927\u59d1\u5988\u201d &#8211; <code>\"foo\"<\/code>. \u8fd9\u5c31\u662f\u6700\u7ec8\u7ed3\u679c<code>\"foo\"<\/code>\u7684\u7531\u6765\u3002<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>1 || \"foo\" &amp;&amp; 0\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f<code>1<\/code>.<\/p>\n<p>\u636e\u8bf4\u903b\u8f91\u4e0e\u8fd0\u7b97\u7b26(<code>&amp;&amp;<\/code>)\u4f18\u5148\u7ea7\u8981\u5927\u4e8e\u903b\u8f91\u6216(<code>||<\/code>)\u3002\u5982\u679c\u662f\u8fd9\u6837\uff0c\u90a3\u8fd9\u91cc\u7684\u7ed3\u679c\u8fd4\u56de\u5e94\u8be5\u662f\u8fd9\u6837\u5b50\u7684\uff1a<code>1 || \"foo\" &amp;&amp; 0<\/code> \u2192 <code>1 || 0<\/code> \u2192 <code>1<\/code>.<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>(1, 2, 3)\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f<code>3<\/code>.<\/p>\n<p>\u8fd9\u91cc\u8003\u5bdf\u7684\u662f\u9017\u53f7\u8fd0\u7b97\u7b26\uff0c\u4e5f\u79f0\u591a\u91cd\u6c42\u503c\u3002\u9017\u53f7\u8fd0\u7b97\u7b26\u636e\u8bf4\u662f\u4f18\u5148\u7ea7\u6700\u4f4e\u7684\u8fd0\u7b97\u7b26\u3002<br \/>\n\u4e00\u822c\u8868\u73b0\u5f62\u5f0f\u662f\uff1a\u5927\u59d1\u5988\uff0c\u4e8c\u59d1\u5988\uff0c\u4e09\u59d1\u5988\uff0c\u2026\u2026N\u59d1\u5988\u3002<br \/>\n\u8fd0\u7b97\u89c4\u5219\u5982\u4e0b\uff1a\u6298\u817e\u5927\u59d1\u5988\uff0c\u6298\u817e\u4e8c\u59d1\u5988\uff0c\u6298\u817e\u4e09\u59d1\u5988\uff0c\u2026\u2026\u6298\u817eN\u59d1\u5988\uff0c\u6700\u540e\u8fd4\u56de\u7684N\u59d1\u5988\u7684\u8fd4\u56de\u503c\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u8fd9\u91cc<code>1, 2, 3<\/code>\u5c31\u662f\u6298\u817e\u4e86<code>1<\/code>\uff0c\u6298\u817e\u4e86<code>2<\/code>\uff0c\u6298\u817e\u4e86<code>3<\/code>\u5e76\u4e14\u8fd4\u56de\u4e86<code>3<\/code>\u7684\u8fd4\u56de\u503c\u3002\u56e0\u6b64\uff0c\u7ed3\u679c\u662f<code>3<\/code>.<\/p>\n<p>\u597d\uff0c\u73b0\u5728\u63d0\u95ee\uff1a<code>alert(1, 2, 3);<\/code>\u7684\u5f39\u51fa\u503c\u662f\uff1f<\/p>\n<p>\u7ed3\u679c\u662f<code>3<\/code>\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u662f\u4e0d\u53ef\u80fd\u7684\uff01\u6b63\u786e\u7ed3\u679c\u662f<strong>1<\/strong>.<\/p>\n<p>\u4e0d\u8981\u56f0\u6270\u3002\u539f\u56e0\u5f88\u7b80\u5355\uff0c<code>alert<\/code>\u8eab\u540e\u7684<code>()<\/code>\u5b9e\u9645\u4e0a\u4e5f\u662f\u4e00\u79cd\u8fd0\u7b97\u7b26\uff0c\u8fd9\u91cc\u6307\u51fd\u6570\u8c03\u7528\uff0c\u4f18\u5148\u7ea7\u76f8\u5f53\u7684\u9ad8\u3002\u8fd9\u91cc\uff0c<code>1, 2, 3<\/code>\u5df2\u7ecf\u88ab\u5974\u5f79\u6210<code>alert<\/code>\u65b9\u6cd5\uff08\u5f39\u51fa\u7b2c\u4e00\u4e2a\u53c2\u6570\u503c\uff09\u7684\u53c2\u6570\u4e86\uff0c\u56e0\u6b64\uff0c\u5f39\u51fa\u7684\u662f<code>1<\/code>. <\/p>\n<p>\u5982\u679c\u662f<code>alert((1, 2, 3));<\/code>\u5219\u5f39\u51fa\u7684\u5c31\u662f<code>3<\/code>\u4e86\u3002<\/p>\n<p><strong>\u5b9e\u7528\u6027<\/strong><br \/>\n\u4e3e\u4e2a\u5f88\u7b80\u5355\u7684\u4f8b\u5b50\uff0c<code>i<\/code>, <code>j<\/code>\u4e24\u4e2a\u53d8\u91cf\u540c\u65f6\u9012\u589e\uff0c\u53ef\u80fd\u6211\u4eec\u4f1a\u8fd9\u6837\u5199\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>\nvar i=1;\nvar j=1;\ni+=1;\nj+=2;\n<\/pre>\n<\/div>\n<p>\u6211\u4eec\u53ef\u4ee5\u501f\u52a9\u9017\u53f7\u8fd0\u7b97\u7b26\u83b7\u5f97\u66f4\u597d\u5730\u9605\u8bfb\u4f53\u9a8c\uff0c\u81f3\u4e8e\u6027\u80fd\u662f\u5426\u6709\u63d0\u9ad8\uff0c\u6211\u4e2a\u4eba\u5e76\u4e0d\u6e05\u695a\uff0c\u5c31\u7b97\u6709\uff0c\u5dee\u5f02\u4e5f\u662f\u53ef\u4ee5\u5ffd\u7565\u7684\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>\nvar i=1, j=1;\ni+=1, j+=2;\n<\/pre>\n<\/div>\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>x = { shift: [].shift };\nx.shift();\nx.length;\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662fIE6\/IE7 <code>undefined<\/code>, \u5176\u4ed6\u6d4f\u89c8\u5668<code>0<\/code>. \u4e0d\u8fc7\uff0c\u4e2a\u4eba\u89c2\u70b9\uff0cIE6\/IE7\u5176\u5b9e\u5e76\u4e0d\u5c5e\u4e8e\u8fd9\u4e2a\u9898\u76ee\u7684\u8003\u5bdf\u6d4f\u89c8\u5668\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u7740\u91cd\u8ba8\u8bba\u4e3a\u4f55IE8+\u7b49\u6d4f\u89c8\u5668\u4e3a\u4f55\u7ed3\u679c\u662f<code>0<\/code>.<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u4e86\u89e3\u4e0b\u6570\u7ec4\u7684<code>shift<\/code>\u65b9\u6cd5\u3002 \u6211\u4e2a\u4eba\u4e00\u822c\u628a<code>pop\/push<\/code>\u5f52\u4e3a\u4e00\u5bf9\u57fa\u53cb\uff0c\u79fb\u9664\u5c3e\u90e8\u5143\u7d20\u548c\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\uff0c\u90fd\u662f\u505a\u626b\u5c3e\u5de5\u4f5c\u7684\u3002<code>shift\/unshift<\/code>\u5f53\u4f5c\u53e6\u5916\u4e00\u5bf9\u57fa\u53cb\uff0c\u79fb\u9664\u5934\u90e8\u5143\u7d20\u548c\u5934\u90e8\u6dfb\u52a0\u5143\u7d20\uff0c\u90fd\u662f\u5728\u5934\u90e8\u6253\u70b9\u7684\u3002\u8bb0\u4f4f\uff0c<em>\u5355\u8bcd\u5b57\u7b26\u4e2a\u6570\u5c11\u7684(<code>pop<\/code>, <code>shift<\/code>)\u90fd\u662f\u505a\u5220\u9664\u7684<\/em>\uff0c\u8fd9\u6837\u8bb0\u5fc6\u5c31\u4e0d\u4f1a\u6df7\u6dc6\u4e86\u3002<\/p>\n<p>\u4ece\u5916\u8868\u4e0a\u770b\uff0c<code>shift<\/code>\u65b9\u6cd5\u79fb\u9664\u6570\u7ec4\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u5e76\u8fd4\u56de\u8fd9\u4e2a\u5143\u7d20\u3002\u5982\u679c\u8fd9\u4e2a\u6570\u7ec4\u662f\u4e2a\u7a7a\u6570\u7ec4\uff0c\u5219\u8fd4\u56de<code>undefined<\/code>. \u4e00\u822c\u800c\u8a00\uff0c<code>shift<\/code>\u64cd\u4f5c\u4f1a\u6539\u53d8\u540e\u9762\u6240\u6709\u6570\u7ec4\u9879\u5728\u5185\u5b58\u4e2d\u7684\u5730\u5740\uff0c\u56e0\u6b64\uff0c\u76f8\u6bd4<code>pop<\/code>\u65b9\u6cd5\u8981\u6162\u5f97\u591a\u3002<\/p>\n<p>\u4ece\u5185\u5728\u6765\u770b\uff0c<code>shift<\/code>\u8fd8\u80fd\u7ed9\u5bf9\u8c61\u81ea\u52a8\u6dfb\u52a0<code>length<\/code>\u5c5e\u6027\u3002<del datetime=\"2013-05-07T11:17:59+00:00\">Mozilla\u5f00\u53d1\u8005\u4e2d\u5fc3(MDC)<\/del>Mozilla\u5f00\u53d1\u8005\u7f51\u7edc(MDN &#8211; Mozilla Developer Network)\u7684\u89e3\u91ca<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/JavaScript\/Reference\/Global_Objects\/Array\/shift\">\u662f\u8fd9\u6837\u5b50\u7684<\/a>\uff1a<\/p>\n<blockquote><p><code>shift<\/code> is intentionally generic; this method can be <code>called<\/code> or <code>applied<\/code> to objects resembling arrays. Objects which do not contain a length property reflecting the last in a series of consecutive, zero-based numerical properties may not behave in any meaningful manner.<\/p><\/blockquote>\n<p>\u7b80\u4f53\u4e2d\u6587\u8868\u793a\u5c31\u662f\uff08\u8fd9\u91cc\u7684\u91ca\u4e49\u81ea\u5df1\u53ea\u670980%\u786e\u8ba4\uff0c\u82e5\u6709\u4e0d\u51c6\u786e\uff0c\u8bf7\u6781\u529b\u6307\u8bc1<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/30.gif\" align=\"absmiddle\">\uff09\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201305\/dahuangya.jpg\" width=\"119\" height=\"120\" alt=\"\u5927\u9ec4\u9e2d\" class=\"alignright ml20\" \/><\/p>\n<blockquote><p><code>shift<\/code>\u53ef\u4ee5\u6709\u610f\u6cdb\u5316\uff08\u53d8\u8eab\u6210\u9e2d\u5b50\uff09\uff1b\u8be5\u65b9\u6cd5\u53ef\u4ee5\u88ab\u7c7b\u6570\u7ec4\u5bf9\u8c61<code>call<\/code>\u6216\u8005<code>apply<\/code>. \u5bf9\u8c61\u5982\u679c\u6ca1\u6709<code>length<\/code>\u5c5e\u6027\uff0c\u53ef\u80fd\u4f1a\u4ee5\u65e0\u610f\u4e49\u7684\u65b9\u5f0f\u5728\u6700\u540e\u53cd\u5c04\u4e00\u7cfb\u5217\u8fde\u7eed\uff0c\u57fa\u4e8e<code>0<\/code>\u7684\u6570\u503c\u5c5e\u6027\u3002<\/p><\/blockquote>\n<p>\u4ec0\u4e48\u610f\u601d\u5462\uff1f\u6211\u4eec\u770b\u4e0b\u9762\u8fd9\u4e2a\u66f4\u5bb9\u6613\u7406\u89e3\u7684\u95ee\u9898\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>x = {};\n[].shift.call(x);\nx.length;\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f<code>0<\/code>. <span class=\"s\">\/\/zxx: IE6\/IE7 <code>undefined<\/code><\/span>.<\/p>\n<p><code>x<\/code>\u5bf9\u8c61\u539f\u672c\u6728\u6709<code>length<\/code>\u5c5e\u6027\uff0c\u5728\u88ab\u6570\u7ec4<code>shift<\/code>\u65b9\u6cd5<code>call<\/code>\u540e\uff0c\u6dfb\u52a0\u4e86\u4e00\u4e2a\u503c\u4e3a<code>0<\/code>\u7684<code>length<\/code>\u5c5e\u6027\u3002\u6b64\u4e3a\u6570\u7ec4<code>shift<\/code>\u65b9\u6cd5\u7684\u6cdb\u5316\u6027\uff0c\u4e13\u4e1a\u672f\u8bed\u4e3a<em>\u6cdb\u578b(generic)<\/em>\u3002\u5176\u57fa\u53cb\u65b9\u6cd5\uff0c\u4f8b\u5982<code>pop<\/code>, <code>push<\/code>\u7b49\u90fd\u662f\u5982\u6b64\u3002<\/p>\n<p>OK, \u56de\u5230\u539f\u9898\uff0c\u5b9e\u9645\u4e0a\uff0c<code>x.shift()<\/code>\u7684\u8c03\u7528\u7b49\u540c\u4e8e<code>[].shift.call(x)<\/code>, \u4e0d\u660e\u767d\uff1f\u770b\u4e0b\u9762\u7684\u4e00\u6b65\u4e00\u6b65\u5206\u6790\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>var x = {\n    shift: function() {\n        console.log(this === x); <span style=\"color: green;\">\/\/ true<\/span>\n    }\n};\nx.shift();<\/pre>\n<\/div>\n<p>\u56e0\u6b64\uff0c\u5728<\/p>\n<div class=\"zxx_code\">\n<pre>x = { shift: [].shift }<\/pre>\n<\/div>\n<p>\u6761\u4ef6\u4e0b\uff0c<br \/>\n<code>x.shift<\/code>\u6267\u884c\u7684\u5c31\u662f<code>[].shift<\/code>\u7684\u6267\u884c\uff0c\u53ea\u4e0d\u8fc7\uff0c<code>[].shift()<\/code>\u51fd\u6570\u4e2d\u7684<code>this<\/code>\u4e0a\u4e0b\u6587\u5c31\u662f<code>x<\/code>(\u56e0\u4e3a<code>this===x<\/code>)\uff0c\u5c31\u7b49\u540c\u4e8e\u76f4\u63a5\u7684<code>[].shift.call(x)<\/code>\u8c03\u7528\u3002<\/p>\n<p>\u8fd9\u6761\u9898\u76ee\u4e2d<code>x<\/code>\u5bf9\u8c61\u7684<code>shift<\/code>\u5c5e\u6027\u540d\u5b9e\u9645\u4e0a\u662f\u7528\u6765\u5e72\u6270\uff0c\u63d0\u9ad8\u89e3\u7b54\u96be\u5ea6\u7684\u523b\u610f\u547d\u540d\u3002\u6211\u4eec\u4f7f\u7528\u5176\u4ed6\u547d\u540d\uff0c\u7ed3\u679c\u4e5f\u662f\u4e00\u6837\u7684\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>x = { shit: [].shift };\nx.shit();\nx.length;\t<span style=\"color: green;\">\/\/ 0<\/span><\/pre>\n<\/div>\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>{foo:1}[0]\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f<code>[0]<\/code>, \u6216\u8005\u8fd9\u79cd\u8868\u73b0\u5f62\u5f0f<code>0 { 0 : 0 }<\/code> &#8211; \u6765\u81eaIE\u63a7\u5236\u53f0.<\/p>\n<p>\u4e0d\u8981\u8bd5\u56fe\u4f7f\u7528<code>alert<\/code>\u6216\u8005\u63a7\u5236\u53f0<code>console.log<\/code>\u8f93\u51fa\uff0c\u8fd9\u53ea\u4f1a\u8fd4\u56de\u4e0d\u4e00\u6837\u7684\u7ed3\u679c<code>undefined<\/code>\uff0c\u54e6\uff1f\u4e3a\u4f55\u4f1a\u6709\u8fd9\u7b49\u5dee\u5f02\uff1f<\/p>\n<p>\u51fa\u9898\u8005james\u5728&#8221;<a href=\"http:\/\/james.padolsey.com\/javascript\/labelled-blocks-useful\/\">Labelled blocks, useful?<\/a>&#8220;\u4e2d\u6709\u8fd9\u6837\u7684\u89e3\u91ca\uff1a<\/p>\n<blockquote><p>Since JavaScript doesn\u2019t have block scope, using a block anywhere other than in the conventional places (if\/while etc.) is almost totally pointless. However, as I mentioned, we could use them to annotate and contain logically related pieces of code&#8230;<\/p><\/blockquote>\n<p>\u610f\u601d\u662f\u8bf4\uff1a<\/p>\n<blockquote><p>\u56e0\u4e3aJavaScript\u6ca1\u6709\u5757\u4f5c\u7528\u57df\uff0c\u6240\u4ee5\uff0c\u5982\u679c\u8bed\u53e5\u5757\u4e0d\u662f\u5e38\u89c4\u4f7f\u7528\uff0c\u5982<code>if\/while<\/code>\u7b49\uff0c\u5176\u51e0\u4e4e\u5c31\u662f\u6253\u9171\u6cb9\u7684\u3002\u751a\u81f3\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u7279\u6027\u6ce8\u91ca\u6216\u8005\u5305\u542b\u76f8\u5173\u7684\u903b\u8f91\u7247\u6bb5\u4ee3\u7801&#8230;<\/p><\/blockquote>\n<p>\u6211\u4eec\u6709\u5fc5\u8981\u597d\u597d\u7406\u89e3\u8fd9\u91cc\u201c\u6253\u9171\u6cb9\u7684\u201d\u610f\u601d\uff0c\u8fd9\u91cc\u7684\u201c\u6253\u9171\u6cb9\u201d\u5e76\u4e0d\u662f\u6307<code>{}<\/code>\u5757\u4e2d\u8bed\u53e5\u662f\u6253\u9171\u6cb9\uff0c\u800c\u662f\u5176\u672c\u8eab\u5c31\u662f\u4e2a\u9171\u6cb9\u3002\u561b\u610f\u601d\uff0c\u5b9e\u4f8b\u8bf4\u660e\u4e00\u5207\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>2 <span style=\"color: graytext;\">\/\/ \u8fd4\u56de\u503c\u4e3a<span style=\"color: green;\">2<\/span><\/span><\/pre>\n<\/div>\n<div class=\"zxx_code\">\n<pre>{2} <span style=\"color: graytext;\">\/\/ \u8fd4\u56de\u503c\u4e3a<span style=\"color: green;\">2<\/span><\/span><\/pre>\n<\/div>\n<div class=\"zxx_code\">\n<pre>str = \"string\" <span style=\"color: graytext;\">\/\/ \u8fd4\u56de\u503c\u4e3a<span style=\"color: green;\">string<\/span><\/span><\/pre>\n<\/div>\n<div class=\"zxx_code\">\n<pre>{ str = \"string\" } <span style=\"color: graytext;\">\/\/ \u8fd4\u56de\u503c\u4e3a<span style=\"color: green;\">string<\/span><\/span><\/pre>\n<\/div>\n<div class=\"zxx_code\">\n<pre>foo: 1 <span style=\"color: graytext;\">\/\/ \u8fd4\u56de\u503c\u4e3a<span style=\"color: green;\">1<\/span><\/span><\/pre>\n<\/div>\n<div class=\"zxx_code\">\n<pre>{ foo: 1 } <span style=\"color: graytext;\">\/\/ \u8fd4\u56de\u503c\u4e3a<span style=\"color: green;\">1<\/span><\/span><\/pre>\n<\/div>\n<p>\u4e5f\u5c31\u662f\u8bf4\u82b1\u62ec\u53f7\u51e0\u4e4e\u5c31\u662f\u7687\u5e1d\u7684\u65b0\u8863\u3002\u56e0\u6b64\uff0c\u8fd9\u91cc\u7684\u7b54\u6848\u5c31\u4e0d\u96be\u7406\u89e3\u4e86\uff0c<code>{foo:1}[0]<\/code>\u5b9e\u9645\u4e0a\u5c31\u662f<code>foo:1; [0]<\/code>. \u8fd4\u56de\u7684\u5c31\u662f<code>[0]<\/code>\u672c\u8eab\u3002<\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc\u53cd\u590d\u51fa\u73b0\u7684\u63aa\u8f9e\u201c\u51e0\u4e4e\u201d\u3002\u201c\u51e0\u4e4e\u9171\u6cb9\u201d\u7684\u6f5c\u53f0\u8bcd\u662f\u6709\u65f6\u5019\u8fd8\u80fd\u9876\u4e2a\u81ed\u76ae\u5320\u3002james\u4e3e\u4e86\u4e2a\u5728\u5757\u4e2d\u4f7f\u7528<code>break<\/code>\u8bed\u53e5\u7684\u4f8b\u5b50\uff0c\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>var x = 1; \nfoo: {\n    x = 2;\n    break foo;\n    x = 3;\n}\nx === 2; <span style=\"color: green;\">\/\/ true<\/span><\/pre>\n<\/div>\n<p>\u975e\u8fd9\u79cd\u60c5\u51b5\u7684<code>break\/continue<\/code>\u53ea\u80fd\u5728<code>switch<\/code>\u8bed\u53e5\u4ee5\u53ca\u5faa\u73af\u4e2d\u4f7f\u7528\u3002\u5f88\u6709\u610f\u601d\u5427\uff0c\u6211\u53cd\u6b63\u662f\u5b66\u4e60\u4e86<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/30.gif\" align=\"absmiddle\">\uff01\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>[true, false][+true, +false]\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f<code>true<\/code>.<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u4e86\u89e3\u4e0b<code>+true<\/code>\u548c<code>+false<\/code>\u662f\u4e2a\u4ec0\u4e48\u4e1c\u897f\u3002<\/p>\n<p>\u60f3\u5fc5\u90fd\u6e05\u695a<code>+1<\/code>\u4e0e<code>-1<\/code>\u662f\u4ec0\u4e48\u4e1c\u4e1c\u3002\u6307\u7684\u662f<code>\u6b63\u65701<\/code>\u4e0e<code>\u8d1f\u65701<\/code>. \u540c\u65f6\uff0c\u7a0d\u5fae\u5bf9JS\u6709\u4e86\u89e3\u7684\u4eba\u4e5f\u6e05\u695a\uff0c<code>true == 1<\/code>, <code>false == 0<\/code>. \u56e0\u6b64\uff0c\u5b9e\u9645\u4e0a\uff0c<code>[+true, +false]<\/code>\u5c31\u662f<code>[+1, +0]<\/code>.<\/p>\n<p><code>[true, false]<\/code>\u4e3a\u6570\u7ec4\uff0c\u540e\u9762\u7684<code>[+true, +false]<\/code>\u5b9e\u9645\u4e3a\u7d22\u5f15\uff0c\u7136\u800c\u7d22\u5f15\u53ea\u9700\u8981\u4e00\u4e2a\u503c\uff0c\u56e0\u6b64\uff0c<code>[+true, +false]<\/code>\u8fd4\u56de\u7684\u5b9e\u9645\u662f\u6211\u4eec\u4e0a\u9762\u63d0\u5230\u7684\u9017\u53f7\u8fd0\u7b97\u2014\u2014\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u503c\uff0c\u4e5f\u5c31\u662f<code>+0<\/code>, \u4e5f\u5c31\u662f<code>0<\/code>. <\/p>\n<p>\u56e0\u6b64\uff0c\u672c\u9898\u7684\u95ee\u9898\u5176\u5b9e\u662f\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>[true, false][0]\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u65fa\u8d22\u4f30\u8ba1\u90fd\u5df2\u7ecf\u660e\u767d\u4e86\uff0c\u5c31\u4e0d\u591a\u8bf4\u4e86\u3002\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>++'52'.split('')[0]\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f<code>6<\/code>.<\/p>\n<p>\u6b64\u9898\u96be\u70b9\u5728\u4e8e\u8fd0\u7b97\u7b26\u7684\u4f18\u5148\u7ea7\uff0c\u770b\u6765\u6709\u5fc5\u8981\u628a\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u90fd\u5c55\u793a\u4e0b\u3002\u53c2\u89c1\u4e0b\u8868\uff08\u6570\u636e\u53d6\u81ea<a href=\"http:\/\/blog.meituo.net\/2010\/08\/29\/%E4%B8%8D%E5%8F%AF%E4%B8%8D%E7%9F%A5%E7%9A%84javascript%E8%BF%90%E7%AE%97%E7%AC%A6%E4%BC%98%E5%85%88%E7%BA%A7\/\">\u7f8e\u62d3blog<\/a>\uff09\uff1a<\/p>\n<table width=\"100%\" border=\"0\" cellspacing=\"1\" class=\"params_table\">\n<tr>\n<th scope=\"col\">&nbsp;<\/th>\n<th scope=\"col\">\u8fd0\u7b97\u7b26<\/th>\n<th scope=\"col\">\u63cf\u8ff0<\/th>\n<\/tr>\n<tr>\n<th scope=\"row\">1<\/th>\n<td>. [] ()<\/td>\n<td>\u5b57\u6bb5\u8bbf\u95ee\u3001\u6570\u7ec4\u4e0b\u6807\u3001\u51fd\u6570\u8c03\u7528\u4ee5\u53ca\u8868\u8fbe\u5f0f\u5206\u7ec4<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">2<\/th>\n<td>++ &#8212; &#8211; ~ ! delete new typeof void<\/td>\n<td>\u4e00\u5143\u8fd0\u7b97\u7b26\u3001\u8fd4\u56de\u6570\u636e\u7c7b\u578b\u3001\u5bf9\u8c61\u521b\u5efa\u3001\u672a\u5b9a\u4e49\u503c<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">3<\/th>\n<td>* \/ %<\/td>\n<td>\u4e58\u6cd5\u3001\u9664\u6cd5\u3001\u53d6\u6a21<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">4<\/th>\n<td>+ &#8211; +<\/td>\n<td>\u52a0\u6cd5\u3001\u51cf\u6cd5\u3001\u5b57\u7b26\u4e32\u8fde\u63a5<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">5<\/th>\n<td>&lt; &lt; &gt;&gt; &gt;&gt;&gt;<\/td>\n<td>\u79fb\u4f4d<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">6<\/th>\n<td>&lt; &lt;= &gt; &gt;= instanceof<\/td>\n<td>\u5c0f\u4e8e\u3001\u5c0f\u4e8e\u7b49\u4e8e\u3001\u5927\u4e8e\u3001\u5927\u4e8e\u7b49\u4e8e\u3001instanceof<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">7<\/th>\n<td>== != === !==<\/td>\n<td>\u7b49\u4e8e\u3001\u4e0d\u7b49\u4e8e\u3001\u4e25\u683c\u76f8\u7b49\u3001\u975e\u4e25\u683c\u76f8\u7b49<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">8<\/th>\n<td>&amp;<\/td>\n<td>\u6309\u4f4d\u4e0e<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">9<\/th>\n<td>^<\/td>\n<td>\u6309\u4f4d\u5f02\u6216<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">10<\/th>\n<td>|<\/td>\n<td>\u6309\u4f4d\u6216<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">11<\/th>\n<td>&amp;&amp;<\/td>\n<td>\u903b\u8f91\u4e0e<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">12<\/th>\n<td>||<\/td>\n<td>\u903b\u8f91\u6216<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">13<\/th>\n<td>?:<\/td>\n<td>\u6761\u4ef6<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">14<\/th>\n<td>= += -=<\/td>\n<td>\u8d4b\u503c\u3001\u8fd0\u7b97\u8d4b\u503c<\/td>\n<\/tr>\n<tr>\n<th scope=\"row\">15<\/th>\n<td>,<\/td>\n<td>\u591a\u91cd\u6c42\u503c<\/td>\n<\/tr>\n<\/table>\n<p>\u4ece\u4e0a\u8868\u53ef\u4ee5\u770b\u51fa\u70b9<code>.<\/code>\u4ee5\u53ca<code>[]<\/code>\u8981\u6bd4<code>++<\/code>\u7684\u4f18\u5148\u7ea7\u9ad8\u3002\u56e0\u6b64\uff0c\u8fd9\u91cc\u7684\u95ee\u9898\u7b49\u540c\u4e8e\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>\nvar result;\nresult = \"52\".split(\"\");\t<span style=\"color: green;\">\/\/ [\"5\", \"2\"]<\/span>\nresult = result[0];\t<span style=\"color: green;\">\/\/ \"5\"<\/span>\nresult = ++result; \t<span style=\"color: green;\">\/\/ 6<\/span>\n<\/pre>\n<\/div>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><br \/>\n\u867d\u7136\u8bf4<code>++[\"5\", \"2\"][0]<\/code>\u7684\u8fd4\u56de\u503c\u662f<code>6<\/code>, \u4f46\u662f\u76f4\u63a5<code>++\"5\"<\/code>\u6216\u8005<code>++5<\/code>\u5374\u662f\u4f1a\u62a5\u9519\u7684\uff08FireBug\u63a7\u5236\u53f0\u663e\u793a<cite>&#8220;invalid increment operand&#8221;<\/cite>\u9519\u8bef\uff09\uff0c\u636e\u8bf4\u662f\u56e0\u4e3a\u53ea\u6709\u53d8\u91cf\u624d\u80fd<code>++<\/code> \u800c<code>'5'<\/code>\u53ea\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>a: b: c: d: e: f: g: 1, 2, 3, 4, 5;\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>5<\/code>.<\/p>\n<p>\u8fd9\u91cc\u9700\u8981\u8bb2\u4e0b\u6807\u8bb0\u8bed\u53e5(Labelled Statements). \u4e0b\u6587\u4e3a\u6211\u7406\u89e3\u7684<a href=\"http:\/\/ecmascript.cn\/#232\">ECMAScript\u6587\u6863\u4e2d\u7684\u89e3\u91ca<\/a>\uff1a<\/p>\n<blockquote><p>\n\u8bed\u53e5\u53ef\u4ee5\u6709\u4e2a\u6807\u7b7e\u524d\u7f00\u3002\u6807\u8bb0\u8bed\u53e5\u53ea\u548c<code>break<\/code>\u6216<code>continue<\/code>\u6807\u8bb0\u7684\u8bed\u53e5\u7ed3\u5408\u4f7f\u7528\uff08\u60f3\u60f3\u7b2c7\u9898\u6700\u540e\u90a3\u4e2a<code>break<\/code>\u7684\u4f8b\u5b50\uff09\u3002ECMAScript\u4e2d\u5e76\u65e0goto\u8bed\u53e5\u3002<\/p>\n<p>ECMAScript\u7a0b\u5e8f\u4e2d\uff0c\u5982\u679c\u6807\u8bb0\u8bed\u53e5\u7684\u6807\u7b7e\u6807\u8bc6\u7b26\u6709\u91cd\u590d\uff0c\u5219\u4f1a\u51fa\u9519\u3002\u6bd4\u65b9\u8bf4<code>a: {a: 1};<\/code>\u5c31\u4f1a\u55dd\u5c41(FireBug\u663e\u793aSyntaxError: duplicate label\u9519\u8bef)\uff0c\u800c<code>a: {b: 1};<\/code>\u7ee7\u7eed\u900d\u9065\u5feb\u6d3b\u3002\u4f46\u662f\uff0c\u8fd9\u5e76\u4e0d\u9002\u7528\u4e8e\u6807\u8bb0\u8bed\u53e5\u4e2d\u6216\u5d4c\u5957\u6216\u76f4\u63a5\u6216\u95f4\u63a5FunctionDeclaration\u4f53\u4e2d\u51fa\u73b0\u7684\u6807\u7b7e\u3002\u5982<code>a: (function() {a: 1});<\/code>\u5c31\u662fOK\u7684\u3002<\/p>\n<p>\u751f\u4ea7\u6807\u8bc6\u7b26(Identifier)\uff1a\u8bed\u53e5\u7684\u6267\u884c\u662f\u901a\u8fc7\u7ed9\u6807\u7b7e\u96c6\u589e\u52a0\u6807\u8bc6\u7b26\uff0c\u7136\u540e\u518d\u6267\u884c\u8bed\u53e5\u3002\u5982\u679c\u6807\u7b7e\u8bed\u53e5\u672c\u8eab\u5c31\u6709\u4e00\u4e2a\u975e\u7a7a\u7684\u6807\u7b7e\u96c6\uff08\u5192\u53f7\u540e\u9762\u7684\u8bed\u53e5\u8fd8\u6709\u7c7b\u4f3c\u7ed3\u6784\uff0c\u4f8b\u5982<code>a: b: 1<\/code>\uff0c<code>b:1<\/code>\u4e3a<code>a<\/code>\u6807\u7b7e\u96c6\u7684\u6807\u7b7e\u8bed\u53e5\uff0c\u4f46\u8fd9\u4e2a\u8bed\u53e5\u672c\u8eab\u5c31\u542b\u6709\u4e00\u4e2a\u6807\u7b7e\u96c6\uff09\uff0c\u5219\u5728\u8bed\u53e5\u6267\u884c\u4e4b\u524d\u8fd9\u4e9b\u6807\u7b7e\u4eec\u6dfb\u52a0\u5230\u6807\u7b7e\u96c6\u4e4b\u4e2d\u3002\u5982\u679c\u8bed\u53e5\u6267\u884c\u7684\u7ed3\u679c\u662f<code>(break, V, L)<\/code>\uff0c\u5176\u4e2dL\u7b49\u4e8e\u6807\u8bc6\u7b26\uff0c\u5219\u4ea7\u751f\u7684\u7ed3\u679c\u662f<code>(normal, V, empty)<\/code>. <span class=\"s\">\/\/zxx: \u6807\u8bc6\u7b26\u5b9e\u9645\u5c31\u662f\u6307\u53d8\u91cf\u540d\u3001\u51fd\u6570\u540d\u3001\u6570\u7ec4\u540d\u7b49. \u6b64\u5904\u6211\u662f\u770b\u4e0d\u61c2\u7684\uff0c\u56e0\u6b64\u65e0\u6cd5\u5177\u4f53\u89e3\u91ca<\/span><\/p>\n<p>\u6267\u884c\u6807\u8bb0\u8bed\u53e5(LabelledStatement)\u4e4b\u524d\uff0c\u5176\u5305\u542b\u7684\u8bed\u53e5\u88ab\u8ba4\u4e3a\u5177\u6709\u4e00\u4e2a\u7a7a\u7684\u6807\u7b7e\u96c6\uff0c\u9664\u975e\u4ed6\u662f\u4e00\u4e2a\u8fed\u4ee3\u8bed\u53e5\u6216switch\u8bed\u53e5\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b,\u5b83\u88ab\u89c6\u4e3a\u62e5\u6709\u4e00\u4e2a\u5355\u4e00\u5143\u7d20\u7ec4\u6210\u7684\u7a7a\u6807\u7b7e\u96c6\u3002\n<\/p><\/blockquote>\n<p>\u4e0a\u9762\u8fd9\u70b9\u4e1c\u897f\u6298\u817e\u4e86\u4e2a\u628a\u5c0f\u65f6\u90fd\u6ca1\u641e\u6e05\u695a\u8981\u8bf4\u7684\u662f\u4ec0\u4e48\uff0c\u8c8c\u4f3c\u4e5f\u4e0d\u80fd\u5f88\u597d\u89e3\u91ca\u8fd9\u91cc\u7684\u7ed3\u679c\uff0c\u6295\u5165\u4e0e\u4ea7\u51fa\u6bd4\u592a\u4f4e\uff0c\u90c1\u95f7\uff01\u53ea\u602a\u529f\u529b\u4e0d\u591f\uff0c\u6216\u8bb8\u8fc7\u4e24\u5e74\u518d\u8fc7\u6765\u770b\uff0c\u5c31\u5f88\u8f7b\u677e\u4e86\u3002<\/p>\n<p>\u540e\u53c8\u641c\u7d22\u4e86\u4e0b\uff0c\u53d1\u73b0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/JavaScript\/Reference\/Statements\/label\"><del datetime=\"2013-05-07T11:17:59+00:00\">MDC<\/del>MDN\u7684\u89e3\u91ca<\/a>\u8981\u901a\u4fd7\u7684\u591a\uff1a<br \/>\n\u6240\u8c13\u6807\u8bb0\u8bed\u53e5\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>label :\n   statement<\/pre>\n<\/div>\n<p>\u5c31\u662f\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>\u6807\u7b7e :\n   \u8bed\u53e5<\/pre>\n<\/div>\n<p>\u5176\u4e2d<code>label<\/code>\u53ef\u4ee5\u662fJavaScript\u4e2d\u4efb\u610f\u975e\u4fdd\u7559\u5173\u952e\u5b57\u7684\u6807\u8bc6\u7b26\uff1b<code>statement<\/code>\u4e2d<code>break<\/code>\u53ef\u4ee5\u7528\u5728\u4efb\u4f55\u6807\u8bb0\u8bed\u53e5\u4e2d\uff0c<code>continue<\/code>\u7528\u5728\u5faa\u73af\u6807\u8bb0\u8bed\u53e5\u4e2d\u3002<\/p>\n<p><strong><del datetime=\"2013-05-07T11:17:59+00:00\">MDC<\/del>MDN\u5efa\u8bae\u4e0d\u4f7f\u7528labels<\/strong><br \/>\n<code>labels<\/code>\u5728JavaScript\u4e2d\u5e76\u4e0d\u5e38\u7528\uff0c\u56e0\u4e3a\u5176\u964d\u4f4e\u4e86\u53ef\u8bfb\u6027\u4ee5\u53ca\u6613\u7406\u89e3\u6027\uff0c\u5c3d\u53ef\u80fd\u907f\u514d\u4f7f\u7528<code>labels<\/code>\u6807\u8bb0\uff0c\u6839\u636e\u4e0d\u540c\u60c5\u51b5\uff0c\u9009\u62e9\u51fd\u6570\u8c03\u7528\u6216\u8005\u629b\u51fa\u9519\u8bef\u3002<\/p>\n<p>\u4e0b\u9762\u4e3a\u4e00\u4e2a\u5178\u578b\u7684\u6807\u8bb0\u8bed\u53e5\u7684\u4f8b\u5b50\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>var i, j;\n \nloop1:\nfor (i = 0; i &lt; 3; i++) {      <span style=\"color: green;\">\/\/ \u9996\u9875\u8bed\u53e5\u6807\u8bb0\u662f \"loop1\"<\/span>\n   loop2:\n   for (j = 0; j &lt; 3; j++) {   <span style=\"color: green;\">\/\/\u7b2c\u4e8c\u4e2a\u8bed\u53e5\u6807\u8bb0\u4e3a \"loop2\"<\/span>\n      if (i == 1 &amp;&amp; j == 1) {\n         continue loop1;\n      } else {\n         console.log(\"i = \" + i + \", j = \" + j);\n      }\n   }\n}\n \n<span style=\"color: green;\">\/\/ \u8f93\u51fa\u662f:\n\/\/   \"i = 0, j = 0\"\n\/\/   \"i = 0, j = 1\"\n\/\/   \"i = 0, j = 2\"\n\/\/   \"i = 1, j = 0\"\n\/\/   \"i = 2, j = 0\"\n\/\/   \"i = 2, j = 1\"\n\/\/   \"i = 2, j = 2\"\n\/\/ \u6ce8\u610f\u662f\u5982\u4f55\u4e0d\u8f93\u51fa \"i = 1, j = 1\"\u548c\"i = 1, j = 2\"\u7684<\/span><\/pre>\n<\/div>\n<p>\u626f\u4e86\u8fd9\u4e48\u591a\uff0c\u56de\u5230\u95ee\u9898\u672c\u8eab\u3002<\/p>\n<p>\u6839\u636e\u89c4\u8303\uff0c<code>a: b: c: ... g:<\/code>\u5728\u8bed\u53e5\u6267\u884c\u4e4b\u524d\u4f1a\u5f52\u5230\u4e00\u4e2a\u6807\u7b7e\u96c6\u4e2d\uff0c\u4e3a\u4e00\u4e2a\u96c6\u5408\u3002\u56e0\u6b64\uff0c\u8d70\u4e2a\u6781\u7aef\u7684\u8bdd\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u4e48\u7406\u89e3\uff1a<br \/>\n<code>abcdefg: 1, 2, 3, 4, 5<\/code>. <code>1, 2, 3, 4, 5<\/code>\u4e00\u5f00\u59cb\u6709\u8bf4\u660e\u7684\u9017\u53f7\u591a\u91cd\u8fd0\u7b97\u5566\u2014\u2014\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u503c\uff0c\u56e0\u6b64\uff0c\u672c\u9898\u5c31\u7c7b\u4f3c\u4e8e\u63d0\u95ee\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>abcdefg: 5\t\/\/ \u8fd4\u56de\u7684\u662f\uff1f<\/pre>\n<\/div>\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>{a: 1, b: 2}[[\"b\"]]\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>FireBug\u63a7\u5236\u53f0\u663e\u793a\uff1aSyntaxError: invalid label.<\/p>\n<p>\u5f97\u77e5\u662f\u8fd9\u4e2a\u7ed3\u679c\u7684\u65f6\u5019\uff0c\u6211\u7684\u61f5\u61c2\u7855\u5927\u7684\u773c\u775b\u7acb\u9a6c\u65e0\u8bed\u6210\u4e86\u4e00\u6761\u7f1d\uff0c\uffe3\ufe4f\uffe3<\/p>\n<p>\u7b2c6\u9898\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u8bb2\u8fc7\uff0cJavaScript\u6ca1\u6709\u5757\u4f5c\u7528\u57df\uff0c\u5757\u672c\u8eab\u51e0\u4e4e\u662f\u4e2a\u9171\u6cb9\uff0c\u56e0\u6b64\u8fd9\u91cc\u7684\u6d4b\u8bd5\u9898\u5b9e\u9645\u7b49\u540c\u4e8e\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>a: 1, b: 2; [[\"b\"]]<\/pre>\n<\/div>\n<p>\u7ed3\u679c\u663e\u793a\uff1aSyntaxError: invalid label. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201305\/2013-05-07_091416.png\" width=\"397\" height=\"197\" alt=\"\u65e0\u6548\u6807\u7b7e\u7684\u9519\u8bef\" class=\"alignnone\" \/><\/p>\n<p>\u73b0\u5728\u7684\u7591\u95ee\u662f\uff0c\u4e3a\u4f55<code>a: 1, b: 2<\/code>\u4f1a\u62a5\u9519\uff1f\u5fae\u535a\u63d0\u95ee\u2026\u2026<\/p>\n<p>30\u5206\u949f\u540e\uff0c<a href=\"http:\/\/weibo.com\/1708684567\">@\u7d2b\u4e91\u5983<\/a>\u7ed9\u51fa\u4e86\u8fd9\u6837\u7684\u89e3\u91ca\uff1a<\/p>\n<blockquote><p>\u9017\u53f7\u8fd0\u7b97\u7b26\u53f3\u4fa7\u5fc5\u987b\u662f\u4e2a\u8868\u8fbe\u5f0f,\u4e0d\u80fd\u662f\u975e\u8868\u8fbe\u5f0f\u7684\u8bed\u53e5,\u8fd9\u4e2a\u4f8b\u5b50\u4e2d<code>a: 1, b: 2<\/code>\u7684\u53f3\u4fa7\u7684<code>b: 2<\/code>\u662f\u4e00\u4e2aLabelledStatement, \u4e0d\u662f\u8868\u8fbe\u5f0f\u3002<\/p><\/blockquote>\n<p>\u6211\u89c9\u5f97\u662f\u76f8\u5f53\u9760\u8c31\u7684\u56de\u7b54\u3002\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>\"b\" + 45\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u5c3c\u739b\u662f\u4e0d\u662f\u611f\u52a8\u5730\u773c\u6cea\u54d7\u5566\u7684\u3002\u8fd9\u79cd\u611f\u89c9\u5c31\u50cf\u662f\u88ab\u540e\u5988\u997f\u4e86\u4e2a\u628a\u6708\uff0c\u5728\u4eca\u5929\u8fd9\u4e2a\u9633\u5149\u660e\u5a9a\u7684\u65e5\u5b50\u8d4f\u4e86\u4e00\u5757\u7ea2\u70e7\u8089\uff0c\u4e00\u4e0b\u5b50\u611f\u52a8\u5730\u773c\u6cea\u55b7\u6cc9\u822c\u6d8c\u51fa\u6765\u3002<\/p>\n<p>\u7ed3\u679c\u662f\uff1a<code>\"b45\"<\/code>. <\/p>\n<p>\u5b57\u7b26\u4e32+\u6570\u503c=\u5b57\u7b26\u4e32\u3002<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>{a:{b:2}}\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>2<\/code>.<\/p>\n<p>\u81ea\u4ece\u7ffb\u8d8a\u4e86\u73e0\u7a46\u6717\u739b\uff0c\u624d\u77e5\u9053\u539f\u6765\u4f58\u5c71\u5c31\u662f\u4e2a\u5c0f\u571f\u5305\u3002\u8fd9\u4e2a\u95ee\u9898\u5df2\u7ecf\u662f\u5c0f\u83dc\u4e86\uff0cJavaScript\u6ca1\u6709\u5757\u4f5c\u7528\u57df\uff0c\u56e0\u6b64\uff0c<code>{a:{b:2}}<\/code>\u8fd1\u4e4e\u4e8e<code>a:b:2<\/code>, \u60f3\u8d77<code>a,b,c,...g<\/code>\u7684\u4f8b\u5b50\u6ca1\u6709\uff0c\u663e\u7136\uff0c\u8fd9\u91cc\u8fd4\u56de\u503c\u662f<code>2<\/code>.\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>(function(){}())\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>undefined<\/code>.<\/p>\n<p>\u51fd\u6570\u5982\u679c\u662f\u7a7a\uff0c\u6216\u8005\u6ca1\u6709\u6307\u5b9a\u8fd4\u56de\u503c\uff0c\u5219\u8fd4\u56de\u7684\u662f<code>undefined<\/code>.<\/p>\n<p>\u5173\u4e8e\u6b64\u9898\uff0c\u6211\u5728\u773c\u775b\u5fae\u535a\u4e0a\u629b\u51fa\u4e86\u8fd9\u4e48\u4e2a\u95ee\u9898\uff1a<cite>(function(){}())\u548c(function(){})()\u8fd9\u4e24\u79cd\u5199\u6cd5\u6709\u4ec0\u4e48\u533a\u522b\u5462\uff1f<\/cite><\/p>\n<p>1\u4e2a\u5c0f\u65f6\u8fc7\u53bb\u4e86\uff0c\u4ee5\u4e0b\u51e0\u4e2a\u8bc4\u8bba\u6bd4\u8f83\u89c1\u8840\uff1a<\/p>\n<blockquote><p><a href=\"http:\/\/weibo.com\/cohlint1q81\">@\u5ddd\u5ddd\u54e5\u54e5\u52e4\u52b3\u81f4\u5bcc<\/a> \u6548\u679c\u662f\u4e00\u6837\u7684,\u5468\u7231\u6c11\u90a3\u672c\u4e66\u4e0a\u63d0\u5230\u4e86\u8bed\u6cd5\u89e3\u8bfb\u4e0a\u7684\u533a\u522b,\u4e0d\u8fc7\u611f\u89c9\u8bb2\u5f97\u4e0d\u662f\u5f88\u6e05\u6670 <\/p>\n<p><a href=\"http:\/\/weibo.com\/itapir\">@\u8c98\u5403\u998d\u9999<\/a> \u62ec\u53f7 \u533f\u540d\u51fd\u6570\u8868\u8fbe\u5f0f\u6267\u884c \u62ec\u53f7 \u8ddf \u62ec\u53f7 \u51fd\u6570\u8868\u8fbe\u5f0f\u5b9a\u4e49 \u62ec\u53f7 => \u8fd4\u56de\u533f\u540d\u51fd\u6570\u53e5\u67c4\u6267\u884c \u7684\u533a\u522b\u2026\u2026 <\/p>\n<p><a href=\"http:\/\/weibo.com\/1900199050\">@_Franky<\/a> \u62bd\u8c61\u8bed\u6cd5\u6811 \u548c \u8fd0\u884c\u65f6 \u65e0\u5dee\u5f02. \u9664\u975e\u8fd9\u4e2a\u89e3\u91ca\u5f15\u64ce\u8111\u6b8b\u4e86. \u56e0\u4e3a\u5206\u7ec4\u8fd0\u7b97\u7b26 &#8220;()&#8221; \u5728\u751f\u6210\u8bed\u6cd5\u6811\u7684\u8fc7\u7a0b\u4e2d\u88ab\u6d88\u9664\u4e86. <a title=\"http:\/\/www.cnblogs.com\/_franky\/archive\/2012\/08\/16\/2641100.html\" href=\"http:\/\/t.cn\/zWTxgKa\">http:\/\/t.cn\/zWTxgKa<\/a> \u8fd9\u7bc7\u6211\u6709\u987a\u9053\u63d0\u5230\u8fc7\u8fd9\u4e2a\u95ee\u9898\n<\/p><\/blockquote>\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>[1,2,3,4,5][0..toString.length]\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u8fd8\u662f\uff1a<code>2<\/code>.<\/p>\n<p>\u672c\u9898\u6d89\u53ca\u7684\u77e5\u8bc6\u70b9\u633a\u591a\u7684\u3002<\/p>\n<p><strong>\u2460 <\/strong>\u9996\u5148\u662f\u8be1\u5f02\u7684\u8fde\u7eed\u4e24\u4e2a\u70b9<code>..<\/code>. \u6211\u4eec\u5728\u5199CSS\u7684\u65f6\u5019\uff0c\u5e38\u5e38\u4f1a\u6709\u8fd9\u6837\u7684\u5199\u6cd5\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>font-size: <span style=\"color:#cd0000;\">.9em<\/span>;\ncolor: rgba(0, 0, 0, <span style=\"color:#cd0000;\">.35<\/span>);<\/pre>\n<\/div>\n<p>\u70b9\u524d\u9762\u5982\u679c\u662f<code>0<\/code>\u5219\u53ef\u4ee5\u81ea\u52a8\u7f3a\u7701\u3002\u8fd9\u6761\u89c4\u5219\u4f3c\u4e4e\u5728JavaScript\u4e2d\u4e5f\u662f\u9002\u7528\u7684\uff0c\u6bd4\u65b9\u8bf4<code>.9<\/code>\uff0c\u8fd4\u56de\u7684\u5c31\u662f<code>0.9<\/code>.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201305\/2013-05-07_111058.png\" width=\"141\" height=\"76\" alt=\"JavaScript\u4e2d\u70b9\u524d\u9762\u81ea\u52a8\u88650\u622a\u56fe\" class=\"alignnone\" \/><\/p>\n<p>\u56e0\u6b64\uff0c\u8fd9\u91cc<code>0..toString<\/code>\u5b9e\u9645\u4e0a\u7b49\u540c\u4e8e<code>0.0.toString<\/code>. \u4e0b\u9762\u6709\u4e2a\u7591\u95ee\u4e86\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u76f4\u63a5<code>0.toString<\/code>\u800c\u662f<code>0.0.toString<\/code>\u8981\u591a\u641e\u51fa\u4e00\u4e2a<code>0<\/code>\u5462\uff1f\u636e\u8bf4\u662f\u8fd9\u6837\u5b50\u7684\uff0c\u6570\u503c\u540e\u9762\u7684\u70b9<code>\u00b7<\/code>\u6709\u4e24\u79cd\u4f5c\u7528\uff0c\u4e00\u79cd\u5c31\u662f\u5f53\u4f5c\u5c0f\u6570\u70b9\u9002\u7528\uff0c\u53e6\u5916\u5c31\u662f\u7528\u505a\u5b57\u6bb5\u8bbf\u95ee\u3002\u663e\u7136\uff0c<code>0.toString<\/code>\u8fd9\u91cc\u7684\u70b9\u4f1a\u88ab\u5f53\u4f5c\u5c0f\u6570\u70b9\uff0c\u4e8e\u662f\uff0c\u76f4\u63a5\u62a5\u9519\u4e86\uff01\u5199\u6210<code>(0).toString<\/code>\u53ef\u4ee5\u907f\u514d\u6b64\u95ee\u9898\u3002\u518d\u6765\u770b\u770b<code>0.0.toString<\/code>, \u663e\u7136\uff0c\u518d\u505a\u89e3\u6790\u7684\u65f6\u5019\uff0c<code>0.0<\/code>\u4e2d\u7684\u70b9\u5f53\u4f5c\u4e86\u5c0f\u6570\u70b9\uff0c\u663e\u7136\uff0c<code>0.0<\/code>\u540e\u9762\u7684\u90a3\u4e2a\u70b9\u6ca1\u6709\u4efb\u4f55\u7406\u7531\u518d\u88ab\u5f53\u4f5c\u5c0f\u6570\u70b9\u4e86\uff08\u5c0f\u6570\u4e0d\u53ef\u80fd\u6709\u4e24\u4e2a\u5c0f\u6570\u70b9\u7684\uff09\uff0c\u800c\u662f\u8868\u793a\u5b57\u6bb5\u8bbf\u95ee\u3002\u4e8e\u662f\uff0c\u4e07\u4e8b\u5927\u5409\uff0c\u9633\u5149\u660e\u5a9a\uff08\u4e0b\u56fe\u7248\u6743\u6240\u6709\uff09\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201305\/0-0-tostring.png\" width=\"300\" height=\"150\" alt=\"\u5c0f\u6570\u70b9\u548c\u5b57\u6bb5\u8bbf\u95ee\u70b9\u7684\u793a\u610f \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" class=\"alignnone\" \/><\/p>\n<p><strong>\u2461 <\/strong>\u4e0b\u9762\u770b\u770b<code>toString<\/code>, <code>toString<\/code>\u4e3aJS\u5185\u7f6e\u65b9\u6cd5\uff0cECMAScript\u89c4\u8303\u4e0a\u8f6c\u6362\u89c4\u5219\u5982\u4e0b\uff1a<\/p>\n<table class=\"params_table\" width=\"100%\" cellpadding=\"0\" cellspacing=\"1\">\n<tbody>\n<tr>\n<th>\u8f93\u5165\u7c7b\u578b<\/th>\n<th>\u7ed3\u679c<\/th>\n<\/tr>\n<tr>\n<td>Undefined<\/td>\n<td>&#8220;undefined&#8221;<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td>&#8220;null&#8221;<\/td>\n<\/tr>\n<tr>\n<td>Boolean<\/td>\n<td>\u5982\u679c\u53c2\u6570\u662f true\uff0c\u90a3\u4e48\u7ed3\u679c\u4e3a &#8220;true&#8221;\u3002<br \/>\u5982\u679c\u53c2\u6570\u662f false\uff0c\u90a3\u4e48\u7ed3\u679c\u4e3a &#8220;false&#8221;\u3002<\/td>\n<\/tr>\n<tr>\n<td>Number<\/td>\n<td>\u7ed3\u679c\u7b49\u4e8e<strong>\u8f93\u5165\u7684\u53c2\u6570<\/strong>\uff08\u4e0d\u8f6c\u6362\uff09\u3002<\/td>\n<\/tr>\n<tr>\n<td>String<\/td>\n<td>\u53c2\u89c1\u4e0b\u6587\u7684\u6587\u6cd5\u548c\u6ce8\u91ca\u3002<\/td>\n<\/tr>\n<tr>\n<td>Object<\/td>\n<td>\u5e94\u7528\u4e0b\u5217\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u8c03\u7528 <code>ToPrimitive<\/code>(<var> \u8f93\u5165\u53c2\u6570 <\/var>, \u6697\u793a <var>\u5b57\u7b26\u4e32\u7c7b\u578b<\/var>)\u3002 <\/li>\n<li>\u8c03\u7528 ToString(Result(1))\u3002 <\/li>\n<li>\u8fd4\u56de Result(2)\u3002<\/li>\n<\/ol>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4ece\u4e0a\u8868\u53ef\u4ee5\u770b\u51fa\uff0c\u6570\u503c\u4f7f\u7528toString\u65b9\u6cd5\u662f\u6709\u53c2\u6570\u7684\u3002<\/p>\n<p>\u5728JavaScript\u4e2d\uff0c\u8fd9\u4e2a\u53c2\u6570\u4ec5<code>1<\/code>\u4e2a\uff0c\u79f0\u4e4b\u4e3a\u201c\u57fa\u201d\uff0c\u51b3\u5b9a\u4e86\u6570\u503c\u8f6c\u6362\u7684\u8fdb\u5236\u5927\u5c0f\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u662f10\u8fdb\u5236\u3002\u4f8b\u5982\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>(10).toString(); <span style=\"color:green;\">\/\/ \"10\"<\/span><\/pre>\n<\/div>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u201c\u57fa\u201d\u4e3a2\u8fdb\u5236\uff0c8\u8fdb\u5236\u621616\u8fdb\u5236\uff0c\u5219\u7ed3\u679c\u5927\u53d8\u6837\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>(10).toString(2); <span style=\"color:green;\">\/\/ \"1010\"<\/span>\n(10).toString(8); <span style=\"color:green;\">\/\/ \"12\"<\/span>\n(10).toString(16); <span style=\"color:green;\">\/\/ \"a\"<\/span><\/pre>\n<\/div>\n<p>\u5728<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=646\">\u5b9e\u73b0\u989c\u8272\u503c16\u8fdb\u5236\u4e0ergb\u8f6c\u5316<\/a>\u7684\u65f6\u5019\uff0c\u8fd9\u4e9b\u57fa\u6570\u53c2\u6570\u5c31\u5f88\u7ba1\u7528\u3002<\/p>\n<p><strong>\u2462 <\/strong>\u6700\u540e\u4e86\u89e3\u4e0b\u51fd\u6570\u7684length\u4e0e\u53c2\u6570\u4e2a\u6570\uff0c\u770b\u8fd9\u4e2a\uff1a<code>(function(){}).length<\/code>\u7684\u7ed3\u679c\u662f<code>0<\/code>. \u4e3a\u4f55\uff1f<br \/>\n \u6bcf\u4e2a<code>function<\/code>\u51fd\u6570\u4f3c\u4e4e\u90fd\u6709\u4e00\u4e2a<strong>\u4e0d\u53ef\u5199<\/strong>\u7684<code>length<\/code>\u5c5e\u6027\uff0c\u5bf9\u5e94\u8fd9\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u4e2a\u6570\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>var fun = function() {};\nfun.length = 3;\n\nfun.length; <span style=\"color:green;\">\/\/ 0<\/span><\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201305\/2013-05-07_143803.png\" width=\"265\" height=\"181\" alt=\"\u51fd\u6570\u7684length\u5c5e\u6027\u4e0d\u53ef\u5199\" class=\"alignnone\" \/><\/p>\n<p><strong>\u2463 <\/strong>\u73b0\u5728\uff0c\u56de\u5230\u6211\u4eec\u7684\u95ee\u9898\uff0c\u4e8b\u60c5\u5c31\u8c41\u7136\u5f00\u6717\u4e86\uff1a<code>[0..toString.length]<\/code>\u5b9e\u9645\u4e0a\u5c31\u662f\u6570\u503c(<code>0.0<\/code>)\u5e94\u7528toString\u65b9\u6cd5\u7684\u53c2\u6570\u4e2a\u6570\u662f\u591a\u5c11\uff1f\u6839\u636e\u4e0a\u9762\u63cf\u8ff0\uff0c\u6570\u503c\u4f7f\u7528<code>toString<\/code>\u8f6c\u6362\u53c2\u6570\u4e2a\u6570\u4e3a<code>1<\/code>\u3002\u4e8e\u662f\uff0c\u672c\u9898\u7ed3\u679c\u5c31\u662f<code>[1,2,3,4,5][1]<\/code> =&gt; <code>2<\/code>.\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>({} + 'b' > {} + 'a')\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>true<\/code>.<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u6700\u5916\u9762\u7684\u62ec\u53f7\u3002\u5982\u679c\u6ca1\u6709\u6700\u5916\u9762\u7684\u62ec\u53f7\uff0c\u5219<code>{}<\/code>\u5219\u51e0\u4e4e\u65e0\u610f\u4e49\uff0c\u4f46\u662f\u8fd9\u91cc\uff0c\u4f5c\u4e3a\u5e38\u89c4\u7528\u6cd5\uff0c<code>{}<\/code>\u8868\u793a\u539f\u751f\u5bf9\u8c61\u3002\u56e0\u6b64\uff0c\u8fd9\u91cc\u7684\u6bd4\u8f83\u5b9e\u9645\u4e0a\u5c31\u662f\u6bd4\u8f83<code>(\"[object Object]b\" > \"[object Object]a\")<\/code>, \u56e0\u6b64\u8fd4\u56de\u7684\u662f<code>true<\/code>.<\/p>\n<p>\u8bf4\u70b9\u9898\u5916\u7684\uff0c\u5982\u679c\u6700\u5916\u90e8\u6ca1\u6709\u62ec\u53f7\uff0c<code>{} + 'b'<\/code>\u8fd4\u56de\u7684\u662f<code>NaN<\/code>. \u4e8e\u662f<code>{} + 'b' > {} + 'a'<\/code>\u53d8\u6210\u4e86\u6bd4\u8f83<code>NaN > NaN<\/code>, \u7ed3\u679c\u4e3a<code>false<\/code>.\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>Number.prototype.x = function(){ return this === 123; };\n(123).x();\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>false<\/code>.<\/p>\n<p>\u6211\u4eec\u8fd9\u91cc\u4f7f\u7528\u4e86\u4e25\u683c\u76f8\u7b49\u3002\u5b9e\u9645\u4e0a<code>this<\/code>\u548c<code>123<\/code>\u5c5e\u4e8e\u4e0d\u540c\u7684\u7c7b\u578b\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>typeof this === \u201cobject\u201d\ntypeof 123 === \u201cnumber\u201d <\/pre>\n<\/div>\n<p>\u56e0\u6b64\uff0c\u7ed3\u679c\u4e3a<code>false<\/code>. \u5982\u679c\u6211\u4eec\u628a\u9898\u76ee\u4fee\u6539\u6210\u5f31\u7b49\u4e8e\uff0c\u5219\u8fd4\u56de\u7ed3\u679c\u5c31\u662f<code>true<\/code>\u4e86\uff0c\u89c1\u4e0b\u622a\u56fe\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>Number.prototype.x = function(){ return this == 123; };\n(123).x();\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201305\/2013-05-07_150408.png\" width=\"464\" height=\"81\" alt=\"\u5f31\u7b49\u4e8e\u7ed3\u679c\u4e3atrue\" class=\"alignnone\" \/>\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>Array(2).join()\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>\",\"<\/code><\/p>\n<p><code>Array(2)<\/code>\u7684\u8fd4\u56de\u503c\u662f<code>[undefined, undefined]<\/code>\uff0c\u56e0\u6b64\uff0c\u5176\u4f7f\u7528join\u8fde\u63a5\u4e4b\u540e\uff0c\u5c31\u662f\u4e2a\u9017\u53f7<code>\",\"<\/code>\uff08\u6570\u7ec4join\u4e3a\u6307\u5b9a\u8fde\u63a5\u7b26\u65f6\u5019\u4f7f\u7528\u9ed8\u8ba4\u7684\u9017\u53f7<code>\",\"<\/code>\uff09\u3002<\/p>\n<p>\u8fd9\u91cc\u6211\u8981\u629b\u51fa\u4e00\u4e2a\u5fae\u535a\u4e0a\u6ca1\u6709\u6ee1\u610f\u89e3\u7b54\u7684\u95ee\u9898\uff1a<code>Array(2)<\/code>\u548c<code>new Array(2)<\/code>\u7684\u533a\u522b\u5728\u4ec0\u4e48\u5730\u65b9\u5462\uff1f \u6c42\u6307\u70b9\u8ff7\u6d25\uff01\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>vars: var vars = vars;\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>undefined<\/code>.<\/p>\n<p>\u73b0\u5728\u770b\u6b64\u9898\u5c31\u7b80\u5355\u591a\u4e86\uff0c\u6807\u8bb0\u8bed\u53e5\uff0c\u8fd4\u56de\u503c\u5c31\u662f<code>var vars = vars<\/code>\u7684\u8fd4\u56de\u503c<code>undefined<\/code>.<\/p>\n<p><code>var vars = vars<\/code>\u5e76\u4e0d\u4f1a\u62a5<code>vars<\/code>\u4e3a\u5b9a\u4e49\u7684\u9519\u8bef\u662f\u5728\u4e8eJS\u7684\u7f6e\u9876\u89e3\u6790\uff0c\u5176\u5b9e<code>var vars = vars<\/code>\u7684\u8fd0\u4f5c\u662f\u8fd9\u6837\u5b50\u7684\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>var vars;\nvars = vars;<\/pre>\n<\/div>\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>{ foo = 123 }\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>123<\/code>.<\/p>\n<p>\u82b1\u62ec\u53f7\u4e0d\u5728\u62ec\u53f7\u4e2d\u3001if\u8bed\u53e5\u6216\u8005\u5faa\u73af\u4e2d\uff0c\u5c5e\u4e8e\u975e\u5e38\u89c4\u9171\u6cb9\u7528\u6cd5\uff0c\u5f62\u540c\u865a\u8bbe\uff0c\u95ee\u9898\u7b49\u540c\u4e8e<code>foo = 123<\/code>\u7684\u8fd4\u56de\u503c\u662f\uff1f\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>x = 1; (function(){return x; var x = 2;}())\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>undefined<\/code>. <\/p>\n<p>\u6b64\u5904\u8003\u5bdf\u7684\u662fJavaScript\u7684\u201c\u9884\u89e3\u6790(hoisting)\u201d\uff0c\u4e5f\u79f0\u201c\u7f6e\u9876\u89e3\u6790\u201d\uff0c\u6211\u4e4b\u524d\u6709<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=1162\">\u7ffb\u8bd1\u8fc7\u76f8\u5173\u6587\u7ae0<\/a>\u3002<\/p>\n<p>\u6240\u8c13\u201c\u9884\u89e3\u6790\u201d\u6307\u7684\u662f\u5728\u5f53\u524d\u7684\u4f5c\u7528\u57df\u5185\uff0c\u65e0\u8bba\u5728\u54ea\u91cc\u53d8\u91cf\u58f0\u660e\uff0c\u5728\u5e55\u540e\uff0c\u5176\u90fd\u5728\u9876\u90e8\u88ab\u201c\u9884\u89e3\u6790\u201d\u4e86\u3002\u56e0\u6b64\uff0c\u672c\u9898\u7684\u5b9e\u9645\u201c\u89e3\u6790\u201d\u662f\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>x = 1; (function(){var x; <span style=\"color:green;\">\/\/ \u6b64\u65f6x\u4e3aundefined<\/span>\nreturn x;  x= 2;}())<\/pre>\n<\/div>\n<p>\u56e0\u6b64\u7ed3\u679c\u662f<code>undefined<\/code>.\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>delete [].length;\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u4e3a<code>false<\/code>.<\/p>\n<p><code>delete<\/code>\u7528\u6765\u5220\u9664\u5bf9\u8c61\u5c5e\u6027\uff0c\u6210\u529f\u5220\u9664\u8fd4\u56de<code>true<\/code>, \u5982\u679c\u5bf9\u65b9\u9632\u5fa1\u5f88\u5f3a\u5220\u4e0d\u52a8\u5219\u8fd4\u56de<code>false<\/code>.<\/p>\n<p>\u6570\u7ec4\u4e2d\u7684<code>length<\/code>\u5c5e\u6027\u662f\u4e0d\u53ef\u5220\u9664\u7684\uff0c\u56e0\u6b64\u8fd9\u91cc\u8fd4\u56de\u7684\u662f<code>false<\/code>.<\/p>\n<p><code>delete<\/code>\u76f8\u5173\u7684\u77e5\u8bc6\u70b9\u662f\u5f88\u591a\u7684\uff0c\u6bd4\u8bf4\u6cd5<code>window.x = 1<\/code>\u8fd9\u91cc\u7684<code>x<\/code>\u53ef\u4ee5\u88ab<code>delete<\/code>. <code>var x =1<\/code>\u8fd9\u91cc\u7684<code>x<\/code>\u5c31\u4e0d\u80fd\u88ab<code>delete<\/code>. \u56fe\u7075\u793e\u533a\u6709\u7bc7\u4e0d\u9519\u7684\u8bd1\u6587\uff1a\u201c<a href=\"http:\/\/www.ituring.com.cn\/article\/details\/7620\">\u7406\u89e3delete<\/a>\u201d\uff0c\u63a8\u8350\u9605\u8bfb\u3002<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>RegExp.prototype.toString = function() {return this.source};\n\/3\/-\/2\/;\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>1<\/code>. <\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u6709\u5982\u4e0b\u4e00\u4e9b\u5c5e\u6027\uff1a<code>source<\/code>, <code>global<\/code>, <code>ignoreCase<\/code>, <code>multiline<\/code>, <code>lastIndex<\/code>. \u5176\u4e2d\uff1a<code>source<\/code>\u5c5e\u6027\u4e3a\u6784\u6210\u6b63\u5219\u8868\u8fbe\u5f0fPattern\u7684\u5b57\u7b26\u4e32\uff1b<code>global<\/code>\u5c5e\u6027\u662f\u4e00Boolean\u503c\uff0c\u8868\u793a\u6b63\u5219\u8868\u8fbe\u5f0fflags\u662f\u5426\u6709<code>\"g\"<\/code>\uff1b<code>ignoreCase<\/code>\u5c5e\u6027\u662f\u4e00Boolean\u503c\uff0c\u8868\u793a\u6b63\u5219\u8868\u8fbe\u5f0fflags\u662f\u5426\u6709<code>\"i\"<\/code>\uff1b<code>multiline<\/code>\u5c5e\u6027\u662f\u4e00Boolean\u503c\uff0c\u8868\u793a\u6b63\u5219\u8868\u8fbe\u5f0fflags\u662f\u5426\u6709<code>\"m\"<\/code>\uff1b<code>lastIndex<\/code>\u5c5e\u6027\u6307\u5b9a\u4ece\u4f55\u5904\u5f00\u59cb\u4e0b\u6b21\u5339\u914d\u7684\u4e00\u4e2a\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u4f4d\u7f6e\u7d22\u5f15\uff0c\u5f53\u9700\u8981\u65f6\u8be5\u503c\u4f1a\u8f6c\u6362\u4e3a\u4e00\u4e2a\u6574\u578b\u6570\u3002<\/p>\n<p><code>RegExp.prototype.toString<\/code>\u6269\u5c55\u6539\u53d8\u4e86\u9ed8\u8ba4\u7684<code>toString<\/code>\u65b9\u6cd5\uff0c\u5f53\u6b63\u5219\u8868\u8fbe\u5f0f\u9700\u8981\u5e94\u7528<code>toString<\/code>\u65b9\u6cd5\u8fdb\u884c\u5b57\u7b26\u4e32\u8f6c\u6362\u7684\u65f6\u5019\uff0c\u8fd4\u56de\u7684\u5c31\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u7684<code>source<\/code>\u5c5e\u6027\u503c\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<code>\/^\\.dd\\d+$\/ + \"\"<\/code>\u7684\u7ed3\u679c\u5c31\u662f<code>\"^\\.dd\\d+$\"<\/code>.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201305\/2013-05-07_163854.png\" width=\"516\" height=\"104\" alt=\"\u6b63\u5219\u8868\u8fbe\u5f0f\u7684source\u503c\u793a\u610f\" class=\"alignnone\" \/><\/p>\n<p>\u4e8e\u662f\uff0c\/3\/-\/2\/\u5b9e\u9645\u4e0a\u7b49\u540c\u4e8e<code>\"3\"-\"2\"<\/code>\uff0c\u56e0\u6b64\u7ed3\u679c\u5c31\u662f<code>1<\/code>.<\/p>\n<p>\u5982\u679c\u6ca1\u6709<code>toString<\/code>\u65b9\u6cd5\u7684\u91cd\u7f6e\uff0c\/3\/-\/2\/\u5b9e\u9645\u4e0a\u7b49\u540c\u4e8e<code>\"\/3\/\"-\"\/2\/\"<\/code>\uff0c\u56e0\u6b64\u7ed3\u679c\u5c31\u662f<code>NaN<\/code>.\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>{break;4;}\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\u62a5\u5982\u4e0b\u9519\u8bef\uff1aSyntaxError: unlabeled <code>break<\/code> must be inside loop or <code>switch<\/code>.<\/p>\n<p>\u610f\u601d\u662f\u2014\u2014\u89e3\u6790\u9519\u8bef\uff1a\u672a\u6807\u8bb0\u7684<code>break<\/code>\u5fc5\u987b\u5728\u5faa\u73af\u6216<code>switch<\/code>\u4e2d\u3002<\/p>\n<p>\u5bf9\u7167\u9519\u8bef\uff0c\u6211\u4eec\u52a0\u4e2a\u6807\u8bb0\uff0c\u4f7f\u4e4b\u6210\u4e3a\u6807\u8bb0\u8bed\u53e5\uff0c\u5c31\u4e0d\u4f1a\u51fa\u9519\u4e86\u3002\u7c7b\u4f3c\u4e0b\u9762\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>foo: { break foo; 4;} <\/pre>\n<\/div>\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>'foo' == new function(){ return String('foo'); };\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u4e3a\uff1a<code>false<\/code>.<\/p>\n<p>\u7531\u4e8e\u8fd9\u91cc\u662f<code>==<\/code>, <code>'foo'<\/code>\u53c8\u662f\u6b63\u5b97\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u6b64\uff0c\u540e\u9762\u7684<code>new...<\/code>\u9700\u8981\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>new function(){ return String('foo'); } + \"\"; <span style=\"color:green;\">\/\/ \"[object Object]\"<\/span><\/pre>\n<\/div>\n<p>\u663e\u7136\uff0c<code>'foo' == \"[object Object]\"<\/code>\u4e3a<code>false<\/code>.<\/p>\n<p>\u672c\u9898\u5982\u679c\u7a0d\u4f5c\u4e00\u70b9\u4fee\u6539\uff0c\u5219\u7ed3\u679c\u5b8c\u5168\u4e0d\u4e00\u6837\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>'foo' == new function(){ return <span style=\"color:#cd0000;\">new<\/span> String('foo'); };\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u4e3a\uff1a<code>true<\/code>.<\/p>\n<p>\u4e3a\u4f55\uff1f<\/p>\n<p>\u5728\u603f\u98de\uff08\u5706\u5fc3\uff09\u201c<a href=\"http:\/\/www.planabc.net\/2008\/02\/20\/javascript_new_function\/\">\u8be6\u89e3new function(){}\u548cfunction(){}()<\/a>\u201d\u4e00\u6587\u4e2d\u5982\u4e0b\u7684\u89e3\u91ca(<span class=\"s\">\/\/zxx: 08\u5e74\u521d\u7684\u6587\u7ae0\u554a\uff0c\u90a3\u4e2a\u65f6\u5019\u6211\u5904\u5728\u88ab\u5973\u795e\u5acc\u5f03\uff0c\u53d1\u594b\u56fe\u5f3a\u7684\u9636\u6bb5\u3002<\/span>)\uff1a<\/p>\n<blockquote><p>\u53ea\u8981<code>new<\/code>\u8868\u8fbe\u5f0f\u4e4b\u540e\u7684<code>constructor<\/code>\u8fd4\u56de\uff08<code>return<\/code>\uff09\u4e00\u4e2a\u5f15\u7528\u5bf9\u8c61\uff08\u6570\u7ec4\uff0c\u5bf9\u8c61\uff0c\u51fd\u6570\u7b49\uff09\uff0c\u90fd\u5c06\u8986\u76d6new\u521b\u5efa\u7684\u533f\u540d\u5bf9\u8c61\uff0c\u5982\u679c\u8fd4\u56de\uff08<code>return<\/code>\uff09\u4e00\u4e2a\u539f\u59cb\u7c7b\u578b\uff08\u65e0<code>return<\/code>\u65f6\u5176\u5b9e\u4e3a<code>return<\/code>\u539f\u59cb\u7c7b\u578b<code>undefined<\/code>\uff09\uff0c\u90a3\u4e48\u5c31\u8fd4\u56de<code>new<\/code>\u521b\u5efa\u7684\u533f\u540d\u5bf9\u8c61\u3002<\/p><\/blockquote>\n<p>\u4ec0\u4e48\u610f\u601d\u5462\uff1f\u4f17\u6240\u5468\u77e5\uff0cJavaScript\u4e2d\u6709<code>5<\/code>\u79cd\u57fa\u672c\u7c7b\u578b\uff08Undefined\u7c7b\u578b\u3001Null\u7c7b\u578b\u3001Boolean\u7c7b\u578b\u3001Number\u7c7b\u578b\u3001String\u7c7b\u578b\uff09\uff0c\u5982\u679c<code>new<\/code>\u540e\u9762\u7684<code>function<\/code> <code>return<\/code>\u7684\u662f\u8fd95\u4e2d\u57fa\u672c\u7c7b\u578b\u4e4b\u4e00\uff0c<code>new<\/code>\u4f1a\u8ba4\u4e3a\u4f60\u662f\u7eaf\u5c4c\u4e1d\uff0c\u4e0d\u7406\u4f60\uff0c\u8fd8\u662f\u8fd4\u56de\u81ea\u5df1\u521b\u5efa\u7684\u533f\u540d\u5bf9\u8c61\uff1b\u5f53\u7136\uff0c\u5982\u679c\u8fd4\u56de\u6570\u7ec4\u554a\u3001\u51fd\u6570\u3001\u5bf9\u8c61\u8fd9\u7c7b\u9ad8\u5bcc\u5e05\uff0c<code>new<\/code>\u7acb\u9a6c\u53d8\u9f9f\u5b59\u5b50\u4e86\uff0c\u8fd4\u56de\u7684\u5c31\u662f\u8fd9\u4e9b\u9ad8\u5bcc\u5e05\u3002<\/p>\n<p>\u7531\u4e8e<code>String(\"foo\")<\/code>\u662f\u5b57\u7b26\u4e32\uff0c\u800c<code>new String(\"foo\")<\/code>\u662f\u5bf9\u8c61\u3002\u56e0\u6b64\uff0c\u524d\u8005\u8fd4\u56de\u7684\u662f\u533f\u540d\u51fd\u6570\u5bf9\u8c61\u2014\u2014\u663e\u7136\u4e0d\u7b49\u4e8e<code>\"foo\"<\/code>\uff1b\u540e\u8005\u5c31\u662f<code>new String(\"foo\")<\/code>\u5bf9\u8c61\uff0c\u52a0\u4e0a<code>\"foo\" == new String(\"foo\")<\/code>\uff0c\u4e8e\u662f\uff0c\u7ed3\u679c\u4e3a<code>true<\/code>.\n<\/li>\n<li>\n<div class=\"zxx_code\">\n<pre>'foo'.split('') + []\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u662f\uff1a<code>\"f,o,o\"<\/code>.<\/p>\n<p>\u8bb0\u4f4f\uff0c<code>\u6570\u7ec4\u52a0\u6570\u7ec4\uff0c\u5b57\u7b26\u6210\u8001\u6bcd<\/code>\u3002<code>'foo'.split('')<\/code>\u7ed3\u679c\u4e3a\u6570\u7ec4<code>[\"f\", \"o\", \"o\"]<\/code>\uff0c\u5176\u53d8\u8eab\u5b57\u7b26\u4e32\u5c31\u662f<code>\"f,o,o\"<\/code>\u8ddf\u540e\u9762\u7684<code>[]<\/code>\u4e5f\u5c31\u662f<code>\"\"<\/code>\u76f8\u52a0\uff0c\u5c31\u662f\u6700\u7ec8\u7684<code>\"f,o,o\"<\/code>\u4e86\u3002<\/p>\n<p>\u4e0b\u9762\u8003\u8003\u4f60\uff0c<\/p>\n<div class=\"zxx_code\">\n<pre>[1, 2] + [3, 4]\t<span style=\"color: graytext;\">\/\/\u8fd4\u56de\u7684\u662f\uff1f<\/span><\/pre>\n<\/div>\n<p>\u662f\u4e0d\u662f<code>\"1,2,3,4\"<\/code>\uff1f\u606d\u559c\u4f60\uff0c<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/99.gif\" align=\"absmiddle\">\uff0c\u56de\u7b54\u2026\u2026\u2026\u2026\u9519\u8bef\uff01<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/64.gif\" align=\"absmiddle\"><\/p>\n<p>\u8fd9\u53c8\u662f\u6574\u54ea\u6837\u554a\uff01\u54e5\uff0c\u4f60\u53ea\u662f\u7a0d\u5fae\u7c97\u5fc3\u4e86\u70b9\u3002<code>[1, 2]<\/code>\u53d8\u6210\u5b57\u7b26\u4e32\u662f<code>\"1,2\"<\/code>, <code>[3, 4]<\/code>\u53d8\u6210\u5b57\u7b26\u4e32\u662f<code>\"3,4\"<\/code>\uff0c\u56e0\u6b64\u4e24\u8005\u76f8\u52a0\u662f<code>\"1,23,4\"<\/code>\u800c\u4e0d\u662f<code>\"1,2,3,4\"<\/code>.<\/p>\n<p>\u7a7a\u6570\u7ec4\u5b9e\u9645\u4e0a\u662f\u4e2a\u5f88\u6709\u610f\u601d\u7684\u4e1c\u897f\u3002<\/p>\n<div class=\"zxx_code\">\n<pre>[] == 0 <span style=\"color:green;\">\/\/true<\/span>\n!0 <span style=\"color:green;\">\/\/ true<\/span>\n![] <span style=\"color:green;\">\/\/ false<\/span><\/pre>\n<\/div>\n<p>\u7eaf\u5c5e\u9898\u5916\u4e1c\u897f\uff0c\u5c31\u4e0d\u6269\u5c55\u4e86\u3002\n<\/li>\n<\/ol>\n<h3>\u4e09\u3001\u516c\u5b50\u6765\u65f6\u96ea\u82b1\u98d8\uff0c\u516c\u5b50\u79bb\u53bb\u77e5\u4e86\u53eb<\/h3>\n<p>\u4e0d\u5bb9\u6613\u554a\uff0c\u7ec8\u4e8e\u770b\u5230\u7ed3\u5c3e\u4e86\uff0c\u4ece\u4e94\u4e00\u524d\u5199\u5230\u4e94\u4e00\u540e\u3002<\/p>\n<p>\u6b63\u5982\u5f00\u59cb\u63d0\u5230\u4e86\uff0c\u7eaf\u5c5e\u4e2a\u4eba\u7406\u89e3\uff0c\u867d\u89c2\u70b9\u57fa\u672c\u90fd\u591a\u65b9\u8003\u8bc1\uff0c\u96be\u514d\u8fd8\u6709\u4e0d\u51c6\u786e\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u6709\u76f8\u5173\u7814\u7a76\u7684\u540c\u884c\u6307\u6b63\u3002<\/p>\n<p>\u6cb9\u67af\u706f\u5c3d\uff0c\u60f3\u4e0d\u51fa\u4ec0\u4e48\u6cb9\u9ea6\u7684\u8bdd\u8bed\u4e86\uff0c\u5c31\u8fd9\u6837\u5427\u3002\u6211\u4e2a\u4eba\u662f\u5b66\u5230\u5f88\u591a\u4e1c\u897f\uff0c\u5e0c\u671b\u5bf9\u60a8\u7684\u5b66\u4e60\u4e5f\u80fd\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u6587\u7ae0\u7684\u4e00\u4e9b\u63d0\u95ee\u6b22\u8fce\u56de\u7b54\uff0c\u60a8\u7684\u56de\u7b54\u4f1a\u5bf9\u5176\u4ed6\u8fc7\u6765\u5b66\u4e60\u7684\u4eba\u63d0\u4f9b\u5f88\u591a\u7684\u5e2e\u52a9\uff0c\u4eba\u7684\u4ef7\u503c\u4e0d\u6b63\u662f\u5728\u4e8e\u7559\u4e0b\u4ec0\u4e48\u5417\uff1f<img decoding=\"async\" src=\"http:\/\/mat1.gtimg.com\/www\/mb\/images\/face\/14.gif\" align=\"absmiddle\"><\/p>\n<p>\u672b\u4e86\uff0c\u9644\u4e0aECMAScript5.1\u4e2d\u6587\u7248\u94fe\u63a5\uff1a<a href=\"http:\/\/ecmascript.cn\/\">http:\/\/ecmascript.cn\/<\/a><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u4fee\u6539\u4e8e\u66f4\u65b0\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u77e5\u8bc6\u7684\u8bef\u5bfc\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3223\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=3223<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n<div class=\"hidden\">\n<p>\u89c9\u5f97\u8fd9\u91cc\u7684\u6587\u7ae0\u4e0d\u9519\uff0c\u5e0c\u671b\u4ed6\u4e00\u76f4\u8d70\u4e0b\u53bb\uff1f\u60a8\u53ef\u4ee5\uff1a<a target=\"_blank\" href=\"https:\/\/me.alipay.com\/zhangxinxu\" title=\"\u5c0f\u5c0f\u8d5e\u52a9\u5927\u5927\u5e2e\u52a9\"><img loading=\"lazy\" decoding=\"async\" src=\"\/wordpress\/wp-content\/themes\/default\/images\/pay_encourage.png\" width=\"159\" height=\"37\" alt=\"\u652f\u4ed8\u9f13\u52b1\" align=\"absmiddle\" \/><\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p><a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=3223\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201305\/25-js-quiz.jpg\" height=\"170\" width=\"550\" class=\"imgpad mb10\" title=\"\u70b9\u51fb\u67e5\u770b\u672c\u6587\" \/><\/a><br \/>\n\u65f6\u5149\u5189\u5189\uff0c\u6216\u591a\u6216\u5c11\u89c1\u8fc7\u4e00\u4e9bJavaScript\u76f8\u5173\u7684\u9898\u76ee\uff0c\u5176\u4e2d\u5f88\u591a\u5c5e\u4e8e\u53d8\u6001\u7ea7\u522b\u7684\uff01\u5404\u79cd\u5947\u602a\u7b26\u53f7\u5199\u6cd5\u62fc\u5728\u4e00\u8d77\u3001\u5c3c\u739b\u8fd8\u6709\u517c\u5bb9\u6027\u95ee\u9898\uff0c\u4f30\u8ba1\u8fbe\u683c\u62c9\u65af\u90fd\u4e0d\u77e5\u9053\u7b54\u6848\u3002<br \/>\n\u5bf9\u4e8e\u8fd9\u79cd\u6574\u5f97\u4eb2\u5988\u90fd\u4e0d\u8ba4\u8bc6\u7684\u53d8\u6001\u95ee\u9898\uff0c\u5b9e\u9645\u4e0a\u662f\u6ca1\u6709\u4ec0\u4e48\u53c2\u8003\u4ef7\u503c\u7684\u3002\u597d\u6bd4\u8981\u8003\u5bdf\u5916\u661f\u4eba\u5bf9\u4eba\u7c7b\u7684\u4e86\u89e3\uff0c\u7ed3\u679c\u4f60\u90a3\u4e0b\u9762\u8fd9\u8d27\u6765\u505a\u6d4b\u8bd5\uff0c\u770b\u5230\u4eb2\u621a\u7684\u5916\u661f\u4eba\u4e00\u5b9a\u4f1a\u4e91\u91cc\u96fe\u91cc\u7684\uff0c\u4f46\u6709\u610f\u4e49\u5417\uff1f<\/p>\n<p>\u597d\u7684JavaScript\u6d4b\u8bd5\u9898\u76ee\u5e94\u8be5\u662f\uff1a\u95e8\u5916\u6c49\u89c1\u4e86\u76b1\u7709\uff0c\u884c\u5bb6\u89c1\u4e86\u7591\u60d1\u9898\u76ee\u662f\u4e0d\u662f\u7b80\u5355\u4e86\u70b9\uff0c\u540c\u65f6\u8003\u5bdf\u70b9\u8986\u76d6\u5168\u9762\u3002<\/p>\n<p>\u8fd9\u91cc\u8981\u4ecb\u7ecd\u7684\u201dAnother JavaScript quiz\u201c\u4e2d\u7684\u9898\u76ee(by\u975e\u70ed\u706b\u961f\u7684\u8a79\u59c6\u65af)\u4e0d\u662f\u5c5e\u4e8e\u53d8\u6001\u9898\u76ee\uff0c\u800c\u662f\u4ecb\u4e8e\u53d8\u6001\u4e0e\u4e0d\u53d8\u6001\u4e4b\u95f4\uff0c\u56e0\u6b64\uff0c\u5b9e\u9645\u4e0a\u9762\u8bd5\u4ef7\u503c\u4e0d\u53ca\u683c\uff0c\u4f46\u662f\u5b66\u4e60\u4ef7\u503cgood\uff0c\u6545\u62ff\u6765\u8bf4\u8bf4\u2026\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[180],"tags":[13,806,504,509,669,803,222,805,511,804,802,502],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/3223"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3223"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/3223\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}