{"id":904,"date":"2022-03-10T21:23:39","date_gmt":"2022-03-10T13:23:39","guid":{"rendered":"http:\/\/www.henrycome.com\/wordpress\/?p=904"},"modified":"2022-03-10T21:23:39","modified_gmt":"2022-03-10T13:23:39","slug":"20220310212313","status":"publish","type":"post","link":"http:\/\/www.henrycome.com\/wordpress\/202203102123\/904","title":{"rendered":"P26-31\u51fd\u6570-\u58f0\u660e->\u9012\u5f52.js"},"content":{"rendered":"<pre><code class=\"language-javascript\">\/*P26-\u51fd\u6570\u58f0\u660e\u51fd\u6570*\/\n\n\/\/\u51fd\u6570\u63d0\u9ad8\u590d\u7528\u6027\uff0c\u51fd\u6570\u5f0f\u7f16\u7a0b\uff0c\u526a\u77ed\u7075\u6d3b\n\/\/\u51fd\u6570\u7684\u540d\u5b57\u6700\u597d\u4ee5\u52a8\u8bcd\u5f00\u5934\uff0c\u660e\u786e\u8868\u793a\u8981\u505a\u4ec0\u4e48\n\/\/function \u51fd\u6570\u540d\u5c0f\u62ec\u53f7\uff0c\u8bed\u53e5\u5757\u5c31\u662f{}\uff1a function fun(){}\n\nfunction putInRefrigerator(){\n    console.log(&#039;\u6253\u5f00\u51b0\u7bb1\u95e8&#039;);\n    console.log(&#039;\u628a\u5927\u8c61\u88c5\u8fdb\u53bb&#039;);\n    console.log(&#039;\u5173\u4e0a\u51b0\u7bb1\u95e8&#039;);\n}\n\n\/\/\u53c2\u6570\u653e\u5728\u62ec\u53f7\u5462\uff0c\u7528,\u9694\u5f00\nfunction putAnythingInRefrigerator(something){\n    console.log(&#039;\u6253\u5f00\u51b0\u7bb1\u95e8&#039;);\n    console.log(&#039;\u628a&#039;+something+&#039;\u653e\u8fdb\u53bb&#039;);\n    console.log(&#039;\u5173\u4e0a\u51b0\u7bb1\u95e8&#039;);\n}\n\n\/\/\u5e26\u8fd4\u56de\u503c\u7684\u4f8b\u5b50\nfunction add(a,b){\n    return a+b;\n}\n\n\/\/\u4e0d\u8fd4\u56de\u503c\u7684\u8bdd\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528return\nfunction testNum(num){\n    if(num&lt;10) return;\n    return num &gt;10;\/\/true\u8fd4\u56de\u662fBoolean\u503c\n}\n\nvar getTestNum = testNum(11);\nconsole.log(getTestNum);\/\/true\n\n\/*P27-\u51fd\u6570-\u8c03\u7528*\/\n\n\/\/\u540d\u5b57+()\u5373\u53ef\u8c03\u7528\u3002\nputInRefrigerator();\n\/*\nindex.js:8 \u6253\u5f00\u51b0\u7bb1\u95e8\nindex.js:9 \u628a\u5927\u8c61\u88c5\u8fdb\u53bb\nindex.js:10 \u5173\u4e0a\u51b0\u7bb1\u95e8\n*\/\nputAnythingInRefrigerator(&#039;\u5154\u5b50&#039;);\n\n\/*\nindex.js:15 \u6253\u5f00\u51b0\u7bb1\u95e8\nindex.js:16 \u628a\u5154\u5b50\u653e\u8fdb\u53bb\nindex.js:17 \u5173\u4e0a\u51b0\u7bb1\u95e8\n*\/\nadd(1,2);\nconsole.log(add(1,2));\/\/3\n\n\/\/\u7528\u4e00\u4e2a\u53d8\u91cf\u63a5\u6536\u51fd\u6570\u8fd4\u56de\u503c\nvar result = add(1,2);\nconsole.log(result);\/\/3\n\nconsole.log(add(result,5));\/\/8\n\nconsole.log(testNum(-5));\/\/undefined\nconsole.log(testNum(15));\/\/true\n\n\/*P28-\u51fd\u6570-\u8868\u8fbe\u5f0f*\/\n\/\/\u51fd\u6570\u8868\u8fbe\u5f0f,\u4e0d\u52a0()\uff0c\u6253\u5370\u51fa\u672c\u4f53\uff08\u5b9a\u4e49\uff09\u3002\n\nconsole.log(add);\n\/** \/\/\u4e0b\u9762\u5c31\u662f\u51fd\u6570add\u7684\u5b9a\u4e49\uff0c\u672c\u4f53\u3002\n \u0192 add(a,b){\n    return a+b;\n}\n*\/\n\n\/\/\u53ef\u4ee5\u628aadd\u51fd\u6570\u672c\u4f53\u8d4b\u503c\u7ed9\u53e6\u4e00\u4e2a\u53d8\u91cf\uff0c\u4ea7\u751f\u4e00\u4e2a\u540c\u6837\u529f\u80fd\u7684\u51fd\u6570\nvar plus = add;\nvar res = plus(5,6);\nconsole.log(res);\/\/11\n\n\/\/\u53ef\u4ee5\u628aadd\u51fd\u6570\u672c\u4f53\u8d4b\u503c\u7ed9\u53e6\u4e00\u4e2a\u53d8\u91cf\uff0c\u4ea7\u751f\u4e00\u4e2a\u540c\u6837\u529f\u80fd\u7684\u51fd\u6570\nvar plus = add;\nvar res = plus(5,6);\nconsole.log(res);\/\/11\n\n\/\/\u4e5f\u53ef\u4ee5\u5728\u51fd\u6570\u5b9a\u4e49\u7684\u65f6\u5019\uff0c\u5c31\u76f4\u63a5\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\n\/\/VH:\u8fd9\u65f6\u51fd\u6570\u540d\u5c31\u5931\u53bb\u81ea\u5df1\uff0c\u8c03\u7528\u5c31\u63d0\u793a\u662f\u672a\u88ab\u58f0\u660e,\u4f46\u662f\u53c2\u8003\u4f8b\u5b50\u6765\u8bf4\u5c31\u662fmultiply.name=multiple\u3010\u53ef\u4ee5\u53c2\u8003P26-\u51fd\u6570-\u989d\u5916.js\u91cc\u9762\u7684\u5176\u4ed6\u6d4b\u8bd5\u3011\nvar multiply = function multiple(a,b){\n    return a*b;\n    \/\/\u6b64\u5904\u5f00\u59cb\u4e0d\u8981\u5199\u4ee3\u7801\uff0c\u4e0d\u4f1a\u6267\u884c\uff01\uff01\uff01\n}\nconsole.log(multiply(6,2));\/\/12\nconsole.log(multiply);\/\/\u51fd\u6570\u5b9a\u4e49\u4f53\u0192 multiple(){return a*b;}\n\/\/console.log(multiple);\/\/Uncaught ReferenceError: multiple is not defined\nconsole.log(multiply.name);\/\/multiple\n\n\/\/\u4e5f\u53ef\u4ee5\u5728\u51fd\u6570\u5b9a\u4e49\u7684\u65f6\u5019\uff0c\u5c31\u76f4\u63a5\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\n\/\/\u8fd9\u65f6\uff0c\u51fd\u6570function\u540e\u53ef\u4ee5\u4e0d\u5199\u51fd\u6570\u7684\u540d\u5b57\uff0c\u53eb\u533f\u540d\u51fd\u6570\nvar multiply = function (a,b){\n    return a*b;\n    \/\/\u6b64\u5904\u5f00\u59cb\u4e0d\u8981\u5199\u4ee3\u7801\uff0c\u4e0d\u4f1a\u6267\u884c\uff01\uff01\uff01\n}\nconsole.log(multiply(6,2));\/\/12\n\n\/*P29-\u53d8\u91cf\u548c\u51fd\u6570\u63d0\u5347 *\/\n\/\/\u8fd9\u4e2a\u53ef\u4ee5\u53c2\u8003P26-\u51fd\u6570-\u989d\u5916\u91cc\u9762\u603b\u7ed3\u4e86\u4e00\u4e9b\u5176\u4ed6\u60c5\u51b5\uff0c\u8fd8\u6709\u4e0a\u9762\u8bb2\u5230\u7684\u51fd\u6570\u8868\u8fbe\u5f0f\u7684\u6d4b\u8bd5\n\nconsole.clear();\n\n\/*\u8001\u5e08\u7684\u4f8b\u5b50\uff1a\nx =5 ;\nconsole.log(x);\/\/5,\u56e0\u4e3a\u4e0b\u65b9var x\u4f1a\u63d0\u5347\u5230\u57df\u7684\u6700\u9876\u90e8\u3002\nvar x;\n\/** *\/\n\n\/*\u5176\u5b9e\u4e0b\u65b9\u7684var x\u53ef\u4ee5\u7701\u6389\n\/\/\u56e0\u4e3a\u4e0d\u7528var\u58f0\u660e\u7684\u53d8\u91cf\uff0c\u4e0d\u751f\u6548\uff0c\u4f46\u662f\u76f4\u63a5\u8d4b\u503c\u5c31\u751f\u6548\u3002x = 5\u76f4\u63a5\u8d4b\u503c\u5c31\u751f\u6548\u4e86\u3002\nx =5 ;\nconsole.log(x);\/\/5,\u56e0\u4e3a\u4e0b\u65b9var x\u4f1a\u63d0\u5347\u5230\u57df\u7684\u6700\u9876\u90e8\u3002\n\/** *\/\n\n\/*\u90a3\u4e48\u4e0a\u4e0b\u90fd\u8d4b\u503c\u5462\uff1f\n\/\/\u4e0b\u65b9\u4f8b\u5b50\uff0c\u6253\u5370\u7ed3\u679c\u662f6,\u56e0\u4e3a\u4e0b\u65b9var x\u4f1a\u63d0\u5347\u5230\u57df\u7684\u6700\u9876\u90e8\u3002\n\/\/\u4f46\u8d4b\u503c\u76845\u662f\u5728\u539f\u4f4d\u7f6e\uff0cconsole.log\u6267\u884c\u65f6\u8fd8\u6ca1\u6709\u8fd0\u884cx\u8d4b\u503c5\u3002\nx =6 ;\nconsole.log(x);\/\/6,\nvar x= 5;\n\/** *\/\n\n\/*\u51fd\u6570\u63d0\u5347\n\/\/\u597d\u5904\u662f\uff0c\u628a\u51fd\u6570\u5b9a\u4e49\u90fd\u5199\u5728\u6700\u4e0b\u9762\uff0c\u4e0a\u9762\u90fd\u662f\u4f7f\u7528\u8fc7\u7a0b\uff0c\u6bd4\u8f83\u6e05\u6670\n\/\/\u4e0b\u9762\u7684\u4f8b\u5b50\uff0c\u4e0a\u4e0b\u90fd\u6253\u5370\u7ed3\u679c\u90fd\u662f2\nconsole.log(divide(8,4));\/\/2\nfunction divide(a,b){\n    return a\/b;\n}\nconsole.log(divide(8,4));\/\/2\n\/** *\/\n\n\/*P30-\u51fd\u6570-\u9ed8\u8ba4\u503c*\/\n\/*\u6709\u9ed8\u8ba4\u503c\u7684\u51fd\u6570\uff0c\u4e0d\u7528\u6307\u5b9a\u53c2\u6570\n\nconsole.clear();\n\nfunction greetings(name = &#039;\u5cf0\u534e&#039;){\n    console.log(&#039;\u4f60\u597d\uff0c&#039;+name)\n}\ngreetings();\/\/\u4f60\u597d\uff0c\u5cf0\u534e\n\/** *\/\n\n\/*\u5982\u679c\u4e00\u5b9a\u8981\u4f20\u5165\u7684\u8bdd\uff0c\u90a3\u5c31\u8986\u76d6\u9ed8\u8ba4\u7684\ngreetings(&#039;HenryCome&#039;);\/\/\u4f60\u597d\uff0cHenryCome\n\/** *\/\n\n\/*undefined\u6765\u8865\u53c2\u6570\u7a7a\u4f4d\n\/\/\u6ce8\u610f\uff0c\u8fd9\u91cc\u4e0d\u80fd\u4f7f\u7528null\uff0c\u56e0\u4e3anull\u672c\u8eab\u548c123\u7b49\u662f\u4e00\u6837\u662f\u503c\u3002\nfunction greetings(nameOfMine = &#039;\u5cf0\u534e&#039;,weather){\n    console.log(&#039;\u4f60\u597d\uff0c&#039;+nameOfMine+&#039;\uff0c\u4eca\u5929\u5929\u6c14\uff1a&#039;+weather)\n}\ngreetings(undefined,&#039;\u6674\u5929&#039;);\/\/\u4f60\u597d\uff0c\u5cf0\u534e\uff0c\u4eca\u5929\u5929\u6c14\uff1a\u6674\u5929\n\/** *\/\n\n\/*P31-\u51fd\u6570-\u9012\u5f52*\/\n\/\/\u9012\u5f52\u4e0e\u5faa\u73af\u7c7b\u4f3c\uff0c\u6240\u4ee5\u4e5f\u9700\u8981\u4e00\u4e2a\u6761\u4ef6\u6765\u907f\u514d\u65e0\u9650\u5faa\u73af\u3002\n\/*\n1.\u8001\u5e08\u8bf4\u8fd9\u4e2a\u53ef\u4ee5\u548c\u5faa\u73af\u8f6c\u6362\n2.\u4f46\u662f\u6211\u6ca1\u592a\u660e\u767d\u8fd9\u4e2a\u8fd9\u4e2a\uff1a\u4eff\u4f5b\u5c31\u662f\u5957\u5a03\uff0c\u6253\u5f00\u53d1\u73b0\u8fd8\u6709\u4e0b\u4e00\u5c42\uff0c\u7ee7\u7eed\uff0c\u7136\u540e\u5230\u4e86\u6700\u540e\u518d\u88c5\u8d77\u6765\u3002\n3.if\u91cc\u9762\u7684return\u628a\u503c\u8fd4\u5230\u54ea\u91cc\u5462\uff1fif\u53ea\u662f\u5bfc\u822a\uff0c\u8def\u8fd8\u662f\u4e00\u4f53\u7684\u6211\u5206\u6790\u5c5e\u4e8esum()\u51fd\u6570\u7684\u4e0b\u7ea7\uff0creturn\u5c31\u662f\u8df3\u51fasum()\n4.\u4e00\u4e2a\u51fd\u6570\u5c31\u662f\u4e00\u9996\u6b4c\uff0c\u4f60\u53ef\u4ee5\u5531\uff0c\u6211\u4e5f\u53ef\u4ee5\u5531\u3002\n*\/\n\/*\nconsole.clear;\n\nfunction sum(n){\n    if(n === 1){\n        return 1;\n    }\n    return n + sum(n-1);\n}\nconsole.log(sum(100));\/\/50\n*\/\n\n\/\/1 1 2 3 5 8\u2026\u2026\n\/\/\u6570\u5217\u4ece0\u5f00\u59cb\u7684\uff0c\u6240\u4ee5\uff0c0 1 2 3\u2026\u2026\n\/\/\u90a3\u4e48\u51fd\u6570\u7684\u53c2\u6570num&lt;=1,\u662f\u8bf4\u524d\u4e24\u4f4d\uff0c\u4f4d0,\u4f4d1\n\/\/\uff1f\u95ee\u9898\u90a3\u4e48\u591a\uff0c\u4ee5\u540e\u518d\u8bf4\uff0c\u8001\u5e08\u4e5f\u8bf4\u4e86\u8fd9\u4e2a\u7b49\u4ee5\u540e\u6808\u90a3\u91cc\u5c31\u597d\u591a\u4e86\u3002\nfunction fib(num){\n    if (num &lt;= 1){\n        return 1;\n    }\n    return fib(num-1)+fib(num-2);\n}\nconsole.log(fib(4));<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/*P26-\u51fd\u6570\u58f0\u660e\u51fd\u6570*\/ \/\/\u51fd\u6570\u63d0\u9ad8\u590d\u7528\u6027\uff0c\u51fd\u6570\u5f0f\u7f16\u7a0b\uff0c\u526a\u77ed\u7075\u6d3b \/\/\u51fd\u6570\u7684\u540d\u5b57\u6700\u597d\u4ee5\u52a8\u8bcd\u5f00\u5934\uff0c\u660e\u786e\u8868\u793a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"http:\/\/www.henrycome.com\/wordpress\/wp-json\/wp\/v2\/posts\/904"}],"collection":[{"href":"http:\/\/www.henrycome.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.henrycome.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.henrycome.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.henrycome.com\/wordpress\/wp-json\/wp\/v2\/comments?post=904"}],"version-history":[{"count":1,"href":"http:\/\/www.henrycome.com\/wordpress\/wp-json\/wp\/v2\/posts\/904\/revisions"}],"predecessor-version":[{"id":905,"href":"http:\/\/www.henrycome.com\/wordpress\/wp-json\/wp\/v2\/posts\/904\/revisions\/905"}],"wp:attachment":[{"href":"http:\/\/www.henrycome.com\/wordpress\/wp-json\/wp\/v2\/media?parent=904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.henrycome.com\/wordpress\/wp-json\/wp\/v2\/categories?post=904"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.henrycome.com\/wordpress\/wp-json\/wp\/v2\/tags?post=904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}