{"id":12208,"date":"2020-12-27T00:00:00","date_gmt":"2020-12-26T16:00:00","guid":{"rendered":"https:\/\/fgchen.com\/wpedu2\/2020\/12\/27\/javascript%e5%bf%ab%e9%80%9f%e5%85%a5%e9%96%80\/"},"modified":"2026-03-30T14:39:32","modified_gmt":"2026-03-30T06:39:32","slug":"javascript%e5%bf%ab%e9%80%9f%e5%85%a5%e9%96%80","status":"publish","type":"post","link":"https:\/\/fgchen.com\/wpedu\/2020\/12\/javascript%e5%bf%ab%e9%80%9f%e5%85%a5%e9%96%80\/","title":{"rendered":"JavaScript\u5feb\u901f\u5165\u9580 &#8211; \u57fa\u790e\u7bc7"},"content":{"rendered":"<h1 id=\"mcetoc_1eqibho1m0\"><b>JavaScript Basics\u00a0<\/b><\/h1>\n\n<b>\u5728\u7db2\u9801\u88cf\u5305\u542b\u4e00\u500bJavaScript\u6bb5\uff1a\u00a0<\/b>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">&lt;script type=\"text\/javascript\"&gt;\u00a0\n\n\/\/JS\u7a0b\u5f0f\u78bc\n\n&lt;\/script&gt;<\/pre>\n\n<b>\u5f15\u5165\u4e00\u500b\u5916\u90e8\u7684JavaScript \u6a94\u6848<\/b>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">&lt;script src=\"js\/myscript.js\"&gt;&lt;\/script&gt;<\/pre>\n\n\u7a0b\u5f0f\u4e2d\u7684\u8a3b\u89e3\n\n\u55ae\u884c\u8a3b\u89e3\n\n<b>\/\/\u00a0<\/b>\n\n<span style=\"font-weight: 400\">\u591a\u884c\u8a3b\u89e3<\/span>\n\n<b>\/* comment here *\/\u00a0<\/b>\n\n&nbsp;\n\n<h1 id=\"mcetoc_1eqibivs11\"><b>\u8b8a\u6578\/Variables\u00a0<\/b><\/h1>\n\n<h2 id=\"mcetoc_1eqibjdr83\"><strong>var, const, let\u00a0<\/strong><\/h2>\n\n<b>var\u00a0<\/b>\n\n<span style=\"font-weight: 400\">var\u8b8a\u6578\u53ef\u4ee5\u91cd\u65b0\u5ba3\u544a\u8207\u7d66\u503c\uff0cvar\u8b8a\u6578\u6703\u81ea\u52d5\u5730\u88ab\u63d0\u81f3\u6700\u524d\u982d\u3002<\/span>\n\n<b>const\u00a0<\/b>\n\n<span style=\"font-weight: 400\">\u5e38\u6578\u8b8a\u6578\uff0c\u4e00\u65e6\u5e38\u6578\u8b8a\u6578\u88ab\u5ba3\u544a\u4e26\u4e14\u7d66\u5b9a\u4e00\u500b\u503c\uff0c\u5c31\u4e0d\u80fd\u518d\u6b21\u7d66\u503c\u3002\u53e6\u5916\uff0c\u8981\u4f7f\u7528\u9019\u4e9b\u5e38\u6578\u8b8a\u6578\uff0c\u5e38\u6578\u8b8a\u6578\u7684\u5ba3\u544a\u5fc5\u9808\u8981\u5148\u51fa\u73fe (\u4f7f\u7528\u524d\u5fc5\u9808\u5148\u5ba3\u544a)\u3002<\/span>\n\n<b>let\u00a0<\/b>\n\n<span style=\"font-weight: 400\">\u8b8a\u6578\u53ef\u4ee5\u91cd\u65b0\u7d66\u503c\uff0c\u4f46\u4e0d\u80fd\u91cd\u65b0\u5ba3\u544a\u4e00\u500b\u540c\u540d\u7684\u8b8a\u6578\u3002<\/span>\n\n<h2 id=\"mcetoc_1es6eq6bh0\">\u8b8a\u6578\u7684\u6709\u6548\u7bc4\u570d<\/h2>\n\n\u4e00\u500b\u8b8a\u6578\u82e5\u5ba3\u544a\u5728\u51fd\u5f0f(function)\u5916\u7684\u8a71\uff0c\u6b64\u8b8a\u6578\u7684\u6709\u6548\u7bc4\u570d\u662f&#8221;\u5168\u57df&#8221;\u7684\uff0c\u6240\u6709\u7684\u5730\u65b9\u90fd\u53ef\u4ee5\u4f7f\u7528\u9019\u500b\u8b8a\u6578\uff0c\u5305\u62ec\u5916\u90e8\u7684js\u6a94\u3002\n\n\u8b8a\u6578\u5ba3\u544a\u5728function\u5167\uff0c\u5247\u8b8a\u6578\u53ea\u80fd\u5728\u51fd\u5f0f\u5167\u4f7f\u7528\u3002\n\n&nbsp;\n\n<h2 id=\"mcetoc_1es6e584q0\">Undefined\u8b8a\u6578<\/h2>\n\n\u8981\u4f7f\u7528\u4e00\u500b\u8b8a\u6578\u524d\uff0c\u5fc5\u9808\u5148\u7d66\u4e88\u8a72\u8b8a\u6578\u4e00\u500b&#8221;\u503c&#8221;\uff0c\u6b64\u70ba\u8b8a\u6578\u7684\u521d\u59cb\u5316\u3002\u5426\u5247\u7684\u8a71\uff0c\u6703\u6709undefined\u7684\u932f\u8aa4\u8a0a\u606f\u767c\u751f\u3002\n\n<h2 id=\"mcetoc_1eqibj4nq2\">\u8cc7\u6599\u578b\u614b\/Data Types<\/h2>\n\n\u5728JavaScript\u4e2d\uff0c\u8b8a\u6578\u7684\u578b\u614b\u662f\u4f9d\u64da\u503c\u7684\u578b\u614b\u4f86\u6c7a\u5b9a\u578b\u614b\u3002\n\n\u6578\u503c\u578b\u614b(number)\n\n<b>var age = 23\u00a0<\/b>\n\n\u5b57\u4e32\n\n<b>var a = &#8220;init&#8221;\u00a0<\/b>\n\n\u5e03\u6797\u503c\n\n<b>var c = true\u00a0<\/b>\n\n&nbsp;\n\n<h1 id=\"mcetoc_1eqibkhrq6\"><b>\u904b\u7b97\u5b50\/Operators\u00a0<\/b><\/h1>\n\n<h2 id=\"mcetoc_1eqibknav7\">\u57fa\u672c\u904b\u7b97\u5b50\/Basic Operators<\/h2>\n\n<b>+\u00a0 \u52a0\/Addition\u00a0<\/b>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">let a = 10;\na = +a; \/\/ 10\na = -a; \/\/ -10<\/pre>\n\n&nbsp;\n\n+\u540c\u6642\u4e5f\u662f\u5b57\u4e32\u4e32\u63a5\u904b\u7b97\u5b50\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">let s1 = '110';\nlet s2 = '220';\nconsole.log(s1+s2); \/\/110220\n<\/pre>\n\n&nbsp;\n\n\u4ee5\u4e0b\u7684\u65b9\u5f0f\u6703\u5c07\u5b57\u4e32\u7684\u5f62\u614b\u8f49\u63db\u6210\u6578\u503c\u578b\u614b\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">let s1='110'; \/\/s1\u662f\u5b57\u4e32\u578b\u614b\nlet s2 = +s1; \/\/s2\u662f\u6578\u503c\u578b\u614b\n<\/pre>\n\n&nbsp;\n\n<b>&#8211;\u00a0 \u6e1b\/Subtraction\u00a0<\/b>\n\n<b>*\u00a0 \u4e58\/Multiplication\u00a0<\/b>\n\n<b>\/\u00a0 \u9664\/Division\u00a0<\/b>\n\n<b>%\u00a0 \u53d6\u9918\u6578\u904b\u7b97\/Modulus (remainder)\u00a0<\/b>\n\n&nbsp;\n\n<h2 id=\"mcetoc_1es6f785f1\">\u905e\u589e\u8207\u905e\u6e1b\u904b\u7b97\u5b50<\/h2>\n\n<b>++ \u905e\u589e\/Increment numbers\u00a0<\/b>\n\n<b>&#8212;\u00a0 \u905e\u6e1bDecrement numbers\u00a0<\/b>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">let x= 8;\n++x;\nconsole.log(x); \/\/ 9<\/pre>\n\n\u7b49\u6548\u65bc\uff1a\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">let x = 8;\nx = x + 1;\nconsole.log(x); \/\/ 9<\/pre>\n\n\u8207\u5176\u4ed6\u904b\u7b97\u5b50\u6df7\u5408\uff1a\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">let i = 10, j = 20;\nlet m = i-- + j; \/\/i + j\u5148\u505a\uff0ci--\u5f8c\u505a\nconsole.log(m); \/\/ 30\nconsole.log(i); \/\/ 9\n\ni = 10;\nlet n = --i + j; \/\/i--\u5148\u505a\nconsole.log(n); \/\/ 29\nconsole.log(i); \/\/ 9<\/pre>\n\n&nbsp;\n\n<h2 id=\"mcetoc_1eqibkudi8\">\u6bd4\u8f03\u904b\u7b97\u5b50\/Comparison Operators<\/h2>\n\n<b>== \u7b49\u65bc\/Equal to\u00a0<\/b>\n\n<b>=== \u503c\u8207\u578b\u614b\u7686\u76f8\u7b49\/Equal value and equal type\u00a0<\/b>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">console.log(\"10\" == 10); \/\/ true\nconsole.log(\"10\" === 10); \/\/ false<\/pre>\n\n<b>!= \u4e0d\u7b49\u65bc\/Not equal\u00a0<\/b>\n\n<b>!== \u503c\u8207\u578b\u614b\u7686\u4e0d\u76f8\u7b49\/Not equal value or not equal type\u00a0<\/b>\n\n<b>&gt; \u5927\u65bc\/Greater than\u00a0<\/b>\n\n<b>&lt; \u5c0f\u65bc\/Less than\u00a0<\/b>\n\n<b>&gt;= \u5927\u65bc\u7b49\u65bc\/Greater than or equal to\u00a0<\/b>\n\n<b>&lt;= \u5c0f\u65bc\u7b49\u65bc\/Less than or equal to\u00a0<\/b>\n\n<b>? \u4e09\u5143\u904b\u7b97\u5b50\/Ternary operator\u00a0<\/b>\n\n<h2 id=\"mcetoc_1eqibl95j9\">\u908f\u8f2f\u904b\u7b97\u5b50\/Logical Operators<\/h2>\n\n<h3 id=\"mcetoc_1es7vpcnh1\">&amp;&amp; \u908f\u8f2f\u4e0a\u7684\u4e14\/Logical and<\/h3>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">let x = false,\n    y = true;\n\nconsole.log(x &amp;&amp; y); \/\/ false\n\nlet x = true,\n    y = true;\nconsole.log(x &amp;&amp; y); \/\/ true<\/pre>\n\n&nbsp;\n\n<h3 id=\"mcetoc_1es7vpg052\">|| \u908f\u8f2f\u4e0a\u7684\u6216\/Logical or<\/h3>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">let x = false,\n    y = false;\n\nconsole.log(x || y); \/\/ false\n\nlet x = true,\n    y = false;\nconsole.log(x &amp;&amp; y); \/\/ true<\/pre>\n\n&nbsp;\n\n<h3 id=\"mcetoc_1es7vou3j0\">Short-Circuit<\/h3>\n\n<div>\n<div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">let\u00a0a\u00a0=\u00a00;\nlet\u00a0b\u00a0=\u00a01;\nif\u00a0(\u00a0a\u00a0&gt;\u00a00\u00a0&amp;&amp;\u00a0++b\u00a0&gt;=\u00a02)\u00a0;\u00a0\/\/a\u503c\u70ba0\uff0cb\u503c\u70ba1\uff0c\u4ee5&amp;&amp;\u4f86\u8aaa\uff0c&amp;&amp;\u524d\u9762\u7684\u6558\u8ff0\u82e5\u662ffalse\uff0c&amp;&amp;\u5f8c\u9762\u7684\u6558\u8ff0\u7684\u7d50\u679c\u4e0d\u7ba1\u662ftrue\u662ffalse\u90fd\u4e0d\u8db3\u4ee5\u6c7a\u5b9a\u6574\u500bif\u7684\u7d50\u679c\u662ftrue\u9084\u662ffalse\uff0c\u6240\u4ee5&amp;&amp;\u5f8c\u9762\u7684++b\u5c31\u8df3\u958b\u3002\nif\u00a0(\u00a0a\u00a0&gt;=\u00a00\u00a0&amp;&amp;\u00a0++b\u00a0&gt;=\u00a02)\u00a0;\u00a0\/\/a\u503c\u70ba0\uff0cb\u503c\u70ba2\uff0c\u56e0\u70baa\u00a0&gt;=\u00a00\u00a0\u70batrue\uff0c\u5f8c\u9762\u7684++b\u00a0&gt;=\u00a02\u5c31\u5fc5\u9808\u9032\u884c\u8a55\u4f30\uff0c\u6240\u4ee5\u5148\u5c0db\u9032\u884c+1\uff0cb\u503c\u70ba2\n\n\n\/\/\u540c\u6a23\u7684\u908f\u8f2f\u904b\u7528\u5728 \"||\"\u4e0a\uff0c\u524d\u9762\u662ftrue\u5f8c\u9762\u5c31\u4e0d\u9700\u8a55\u4f30\u5176\u503c\u662f\u5426\u70batrue\u6216false\uff0c\u82e5\u662ffalse\uff0c\u5247\u5fc5\u9808\u8a55\u4f30\u5f8c\u9762\u7684\u6558\u8ff0\u662f\u5426\u70batrue\u6216false\u3002<\/pre>\n&nbsp;\n\n<\/div>\n<\/div>\n\n<b>! \u908f\u8f2f\u4e0a\u7684\u53cd\/Logical not\u00a0<\/b>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">console.log(!undefined); \/\/ true\nconsole.log(!null); \/\/ true\nconsole.log(!20); \/\/false\nconsole.log(!0); \/\/true\nconsole.log(!NaN); \/\/true\nconsole.log(!{}); \/\/ false\nconsole.log(!''); \/\/true\nconsole.log(!'OK'); \/\/false\nconsole.log(!false); \/\/true\nconsole.log(!true); \/\/false<\/pre>\n\n&nbsp;\n\n<p id=\"mcetoc_1es80gfj93\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/www.bestprog.net\/wp-content\/uploads\/2017\/10\/05_02_02_03_06_table_03e.jpg\" width=\"913\" height=\"209\" class=\"alignnone size-full\" \/><\/p>\n\n&nbsp;\n\n<h2 id=\"mcetoc_1eqiblfhda\">\u9010\u4f4d\u5143\u904b\u7b97\u5b50\/Bitwise Operators<\/h2>\n\n<b>&amp; AND statement\u00a0<\/b>\n\n<b>| OR statement\u00a0<\/b>\n\n<b>~ NOT\u00a0<\/b>\n\n<b>^ XOR\u00a0<\/b>\n\n<b>&lt;&lt; Left shift (\u7121\u865f\u6578\u5de6\u79fb)\uff0c\u7b49\u6548\u65bc\u4e58\u6cd5\uff0c\u6bcf\u5de6\u79fb\u4e00\u500b\u4f4d\u5143\uff0c\u6548\u679c\u662f\u4e58\u4ee52\uff0c\u79fb2\u500b\u4f4d\u5143\u5c31\u662f\u4e58\u4ee52\u4e58\u4ee52\u2026\uff0c\u7576\u5de6\u79fb\u5143\u4f4d\u6642\uff0c\u6700\u53f3\u908a\u7684\u4f4d\u5143\u88dc0\u3002<\/b>\n\n<b>&gt;&gt; Right shift (<span>Signed right shift)\uff0c\u6700\u5de6\u908a\u7684\u4f4d\u5143\u4e0d\u8ddf\u8457\u53f3\u79fb(\u4fdd\u7559\u5176\u7b26\u865f\u4f4d\u5143)<\/span><\/b>\n\n<b>&gt;&gt;&gt; Zero fill right shift (\u7121\u865f\u6578\u7684\u53f3\u79fb)\uff0c\u7576\u4f4d\u5143\u53f3\u79fb\u6642\uff0c\u6700\u5de6\u908a\u7684\u4f4d\u5143\u88dc0\uff0c\u7b49\u6548\u65bc\u9664\u6cd5\uff0c\u4f8b4\/2=2\u3002<\/b>\n\n&nbsp;\n\n\u6b64\u90e8\u4efd\u53ef\u53c3\u8003W3 School <a href=\"https:\/\/www.w3schools.com\/js\/js_bitwise.asp\" target=\"_blank\" rel=\"noopener\">JavaScript Bitwise Operations<\/a>\n\n<div><\/div>","protected":false},"excerpt":{"rendered":"<p>JavaScript Basics\u00a0 \u5728\u7db2\u9801\u88cf\u5305\u542b\u4e00\u500bJavaScript\u6bb5\uff1a\u00a0 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[266],"tags":[],"class_list":["post-12208","post","type-post","status-publish","format-standard","hentry","category-266"],"_links":{"self":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/comments?post=12208"}],"version-history":[{"count":1,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12208\/revisions"}],"predecessor-version":[{"id":13640,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/12208\/revisions\/13640"}],"wp:attachment":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/media?parent=12208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/categories?post=12208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/tags?post=12208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}