{"id":930,"date":"2021-12-19T02:04:38","date_gmt":"2021-12-18T18:04:38","guid":{"rendered":"https:\/\/blog.cauchyschwarz.com\/?p=930"},"modified":"2021-12-19T02:05:13","modified_gmt":"2021-12-18T18:05:13","slug":"javascript-tutorial-in-10-days","status":"publish","type":"post","link":"https:\/\/blog.cauchyschwarz.com\/?p=930","title":{"rendered":"JavaScript Tutorial in 10 Days"},"content":{"rendered":"\n<p>Hackerrank\u7f51\u7ad9\u4e0a\u6709\u4e00\u4e2a<a href=\"https:\/\/www.hackerrank.com\/domains\/tutorials\/10-days-of-javascript\">10\u5929\u7684js\u6559\u7a0b<\/a>\uff0c\u4f5c\u4e3a\u4e00\u4e2a\u5199js\u7684\u534a\u540a\u5b50\u6b63\u597d\u53ef\u4ee5\u8fc7\u4e00\u904d\u6765\u5de9\u56fa\u4e0b\u81ea\u5df1\u7684js\u6280\u80fd\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-right counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e0c4d47c1ed\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e0c4d47c1ed\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_0_Hello_World\" >Day 0: Hello World<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_0_DataTypes\" >Day 0: DataTypes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_1_Arithmetic_Operators\" >Day 1: Arithmetic Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_1_Functions\" >Day 1: Functions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_1_Let_and_Const\" >Day 1: Let and Const<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_2_Loops\" >Day 2: Loops<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_3_Arrays\" >Day 3: Arrays<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_3_Try_Catch_and_Finally\" >Day 3: Try, Catch, and Finally<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#String_Basics\" >String Basics<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86\" >\u5f02\u5e38\u5904\u7406<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_4_Create_a_Rectangle_Object\" >Day 4: Create a Rectangle Object<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_4_Classes\" >Day 4: Classes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_5_Template_Literals\" >Day 5: Template Literals<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_5_Arrow_Functions\" >Day 5: Arrow Functions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=930\/#Day_7_Regular_Expressions\" >Day 7: Regular Expressions<\/a><\/li><\/ul><\/nav><\/div>\n<h1 class=\"wp-block-heading\" id=\"day-0-hello-world\"><span class=\"ez-toc-section\" id=\"Day_0_Hello_World\"><\/span>Day 0: Hello World<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>JavaScript\u7a0b\u5e8f\u662f\u4f7f\u7528Unicode\u5b57\u7b26\u96c6\u7f16\u5199\u7684<\/li><li>JavaScript\u5bf9\u5927\u5c0f\u5199\u654f\u611f<\/li><li>JavaScript\u5ffd\u7565token\u4e4b\u95f4\u7684\u7a7a\u767d\u5b57\u7b26\uff0c\u5305\u62ec\u6362\u884c<\/li><li>\u5f53\u4e24\u4e2a\u8bed\u53e5\u5728\u4e0d\u540c\u884c\u4e0a\u7684\u65f6\u5019\uff0cJavaScript\u8bed\u53e5\u672b\u5c3e\u7684\u5206\u53f7\u662f\u53ef\u4ee5\u88ab\u7701\u7565\u7684<\/li><li>JavaScript\u4e2d\u53d8\u91cf\u7684\u547d\u540d\u89c4\u5219\u4e0eC\u8bed\u8a00\u7c7b\u4f3c\uff0c\u53d8\u91cf\u540d\u7531\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\u6216\u7f8e\u5143\u7b26\u53f7\u7ec4\u6210\uff0c\u4e14\u4e0d\u80fd\u7531\u6570\u5b57\u5f00\u5934<\/li><li>JavaScript\u652f\u6301\u7684\u6ce8\u91ca\u65b9\u6cd5\u548cC++\u76f8\u540c<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-0-datatypes\"><span class=\"ez-toc-section\" id=\"Day_0_DataTypes\"><\/span>Day 0: DataTypes<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>JavaScript\u4e2d\u7684\u539f\u59cb\u6570\u636e\u7c7b\u578b(primitive)\u5171\u6709\u516d\u79cd\uff1aNumber, String, Boolean, Symbol, Null, Undefined\u3002\u4ed6\u4eec\u4e0d\u662f\u5bf9\u8c61\u800c\u4e14\u6ca1\u6709\u6210\u5458\u65b9\u6cd5\u3002\u5176\u4ed6\u7684\u6570\u636e\u7c7b\u578b\u90fd\u662fObject<ol><li>Number<br>JavaScript\u4e2d\u7684\u6570\u5b57\u7c7b\u578b\u53ea\u6709\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u4e00\u79cd\u7c7b\u578b\uff0c\u6ca1\u6709\u6574\u6570\u76f8\u5173\u7684\u7c7b\u578b\u3002\u4e00\u4e9b\u7279\u6b8a\u7684\u503c\u5305\u62ec\uff1a<em>Number.MAX_VALUE<\/em>,<em>Number.MIN_VALUE<\/em>,<em>Infinity<\/em>,<em>-Infinity<\/em>,<em>NaN<\/em>,<em>Number.MAX_SAFE_INTEGER<\/em>,<em>Number.MIN_SAFE_INTEGER<\/em>\u3002*Number.isSafeInteger()*\u65b9\u6cd5\u53ef\u4ee5\u7528\u6765\u5224\u65ad\u4e00\u4e2aNumber\u662f\u5426\u662f\u6574\u6570(\u5e76\u4e14\u8be5\u6574\u6570\u4e0d\u80fd\u7531\u5176\u4ed6\u6574\u6570\u8f6c\u4e3a\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570\u5f97\u5230)\u3002<\/li><li>Symbol<br>Symbol\u53ef\u4ee5\u7528\u4e8e\u4f5c\u4e3aObject\u5c5e\u6027\u7684key\u3002<\/li><li>Null<br><em>null<\/em>\u503c\u8868\u793a\u4e00\u4e2a\u7a7a\u5bf9\u8c61\u3002<\/li><li>Undefined<br>\u7528\u4e8e\u8868\u793a\u5bf9\u8c61\u7f3a\u5c11\u67d0\u4e2a\u5c5e\u6027\u6216\u8005\u4e00\u4e2a\u53d8\u91cf\u53ea\u88ab\u58f0\u660e\u6ca1\u6709\u88ab\u5b9a\u4e49\u3002<\/li><\/ol><\/li><li>JavaScript\u4e2d\u7684\u539f\u59cb\u6570\u636e\u7c7b\u578b\u662f<strong>immutable<\/strong>\u7684\uff0c\u5373\u4ed6\u4eec\u7684\u503c\u4e0d\u80fd\u88ab\u6539\u53d8\uff0c\u53ea\u80fd\u58f0\u660e\u65b0\u7684\u53d8\u91cf\u6765\u50a8\u5b58\u5bf9\u539f\u59cb\u6570\u636e\u7c7b\u578b\u53d8\u91cf\u503c\u7684\u64cd\u4f5c\u7ed3\u679c<\/li><li>\u53ef\u4ee5\u7528<em>typeof<\/em>\u6765\u5224\u65ad\u53d8\u91cf\u7c7b\u578b<\/li><li>\u53d8\u91cf\u9700\u8981\u58f0\u660e\u540e\u624d\u80fd\u4f7f\u7528\u6216\u8005\u5728\u58f0\u660e\u7684\u65f6\u5019\u5c31\u5b9a\u4e49\u8be5\u53d8\u91cf\uff0c\u4f46\u662f\u672a\u521d\u59cb\u5316\u7684\u53d8\u91cf\u5176\u503c\u4e3a<em>undefined<\/em><\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-1-arithmetic-operators\"><span class=\"ez-toc-section\" id=\"Day_1_Arithmetic_Operators\"><\/span>Day 1: Arithmetic Operators<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>JavaScript\u652f\u6301**\u7b26\u53f7\uff0c\u8868\u793a\u5e42\u8fd0\u7b97<\/li><li>JavaScript\u7684<em>switch<\/em>\u8bed\u53e5\u53ef\u4ee5\u662f\u4efb\u610f\u7c7b\u578b\uff0c\u4e0d\u540c\u4e8eC\u8bed\u8a00<\/li><li>JavaScript\u4e2d\u7684\u6bd4\u8f83\u7b26\u53f7\uff1a<ul><li><em>==<\/em><br>\u5bf9\u4e8e\u539f\u59cb\u6570\u636e\u7c7b\u578b\u8fdb\u884c\u6309\u503c\u6bd4\u8f83\uff0c\u5bf9\u4e8e\u5bf9\u8c61\u6570\u636e\u7c7b\u578b\u5219\u5224\u65ad\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61<\/li><li><em>!=<\/em><br>\u771f\u503c\u8868\u4e0e==\u76f8\u53cd<\/li><li><em>===<\/em><br>\u4e25\u683c\u76f8\u7b49\uff1a<ul><li>\u64cd\u4f5c\u6570\u5fc5\u987b\u7c7b\u578b\u76f8\u540c<\/li><li>\u64cd\u4f5c\u6570\u5fc5\u987b\u4e25\u683c\u76f8\u7b49<\/li><\/ul><\/li><li><em>!==<\/em><br>\u975e\u4e25\u683c\u76f8\u7b49\uff1a\u771f\u503c\u8868\u4e0e\u4e25\u683c\u76f8\u7b49\u76f8\u53cd<\/li><\/ul><\/li><li>\u51e0\u4e2a\u7279\u6b8a\u7684&#8221;\u5047&#8221;\u503c\uff1a<ul><li><strong>false<\/strong><\/li><li><strong>undefined<\/strong><\/li><li><strong>null<\/strong><\/li><li><strong>0<\/strong><\/li><li><strong>NaN<\/strong><\/li><li><strong>&#8220;&#8221;<\/strong><\/li><\/ul><\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-1-functions\"><span class=\"ez-toc-section\" id=\"Day_1_Functions\"><\/span>Day 1: Functions<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>JavaScript\u901a\u8fc7<strong>function<\/strong>\u5173\u952e\u5b57\uff0c\u58f0\u660e\u4e00\u4e2a\u51fd\u6570\u5bf9\u8c61\uff0c\u51fd\u6570\u9ed8\u8ba4\u8fd4\u56de<strong>undefined<\/strong>\u6216\u8005\u901a\u8fc7<strong>return<\/strong>\u8bed\u53e5\u8fd4\u56de\u5176\u4ed6\u503c<\/li><li>(Function Expression)\u51fd\u6570\u8868\u8fbe\u5f0f\uff1a\u5728\u9700\u8981\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u7684\u5730\u65b9\uff0c\u53ef\u4ee5\u901a\u8fc7\u51fd\u6570\u8868\u8fbe\u5f0f\u76f4\u63a5\u5b9a\u4e49\u4e00\u4e2a\u533f\u540d\u51fd\u6570\u3002\u51fd\u6570\u8868\u8fbe\u5f0f\u548c\u51fd\u6570\u7684\u533a\u522b\u5728\u4e8e\u6ca1\u6709\u51fd\u6570\u540d\u3002<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-1-let-and-const\"><span class=\"ez-toc-section\" id=\"Day_1_Let_and_Const\"><\/span>Day 1: Let and Const<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>\u58f0\u660e\u53d8\u91cf\u7684\u4e09\u79cd\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>var<\/strong><br>\u901a\u8fc7<strong>var<\/strong>\u58f0\u660e\u7684\u53d8\u91cf\u5982\u679c\u4f4d\u4e8e\u51fd\u6570\u4f53\u5185\u5219\u5176\u4f5c\u7528\u57df\u4e3a\u8be5\u51fd\u6570\uff0c\u5426\u5219\u5c31\u662f\u5168\u5c40\u53d8\u91cf<\/li><li><strong>let<\/strong><br>\u901a\u8fc7<strong>let<\/strong>\u58f0\u660e\u7684\u53d8\u91cf\u5176\u4f5c\u7528\u57df\u9650\u4e8e\u5176\u4f4d\u4e8e\u7684<em>block<\/em><\/li><li><strong>const<\/strong><br>\u901a\u8fc7<strong>const<\/strong>\u58f0\u660e\u7684\u53d8\u91cf\u4e0d\u80fd\u88ab\u8d4b\u4e88\u65b0\u503c\uff0c\u5e76\u4e14\u58f0\u660e\u7684\u65f6\u5019\u5fc5\u987b\u88ab\u521d\u59cb\u5316<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-2-loops\"><span class=\"ez-toc-section\" id=\"Day_2_Loops\"><\/span>Day 2: Loops<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>JavaScript\u652f\u6301\u7684\u51e0\u79cd\u5faa\u73af\u8bed\u53e5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>for<\/strong><\/li><li><strong>while<\/strong><\/li><li><strong>do-while<\/strong><\/li><li><strong>for-in<\/strong><br>\u7528\u4e8e\u679a\u4e3eObject\u7684\u5c5e\u6027<\/li><li><strong>for-of<\/strong><br>\u7528\u4e8e\u679a\u4e3e<strong>Array<\/strong>,<strong>Map<\/strong>,<strong>Set<\/strong>,<strong>String<\/strong>,<strong>TypedArray<\/strong>,arguments\u7b49\u5bf9\u8c61<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-3-arrays\"><span class=\"ez-toc-section\" id=\"Day_3_Arrays\"><\/span>Day 3: Arrays<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\">mdn\u5173\u4e8eArray\u7c7b\u7684\u4ecb\u7ecd<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Array\u7c7b\u7684\u5c5e\u6027<br><strong>Array.length<\/strong><\/li><li>\u6210\u5458\u51fd\u6570<ul><li><strong>Array.prototype.push<\/strong><br>\u5728\u672b\u5c3e\u6dfb\u52a0\u5143\u7d20<\/li><li><strong>Array.prototype.forEach<\/strong><br>\u904d\u5386\u6570\u7ec4\u5143\u7d20<\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">fruits.forEach(function(item, index, array) {\n    console.log(item, index)\n})\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Array.prototype.pop<\/strong><br>\u79fb\u9664\u6700\u540e\u4e00\u4e2a\u5143\u7d20<\/li><li><strong>Array.prototype.shift<\/strong><br>\u79fb\u9664\u7b2c\u4e00\u4e2a\u5143\u7d20<\/li><li><strong>Array.prototype.unshift<\/strong><br>\u5728\u6570\u7ec4\u5934\u90e8\u6dfb\u52a0\u5143\u7d20<\/li><li><strong>Array.prototype.indexOf<\/strong><br>\u627e\u5230\u67d0\u4e2a\u5143\u7d20\u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15<\/li><li><strong>Array.prototype.slice<\/strong><br>\u6570\u7ec4\u6d45\u62f7\u8d1d<\/li><li><strong>Array.prototype.sort<\/strong><br>\u6570\u7ec4\u6392\u5e8f,\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u6bd4\u8f83\u51fd\u6570<\/li><li><strong>Array.prototype.splice<\/strong><br>\u79fb\u9664\u4ece\u67d0\u4e2a\u7d22\u5f15\u5f00\u59cb\u7684n\u4e2a\u5143\u7d20<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">let removedItem = fruits.splice(pos, 1)\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-3-try-catch-and-finally\"><span class=\"ez-toc-section\" id=\"Day_3_Try_Catch_and_Finally\"><\/span>Day 3: Try, Catch, and Finally<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"string-basics\"><span class=\"ez-toc-section\" id=\"String_Basics\"><\/span>String Basics<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>string\u53ef\u4ee5\u653e\u5728\u5355\u5f15\u53f7\u6216\u8005\u53cc\u5f15\u53f7\u91cc\u9762\uff0c\u53cc\u5f15\u53f7\u53ef\u4ee5\u653e\u5728\u5355\u5f15\u53f7\u91cc\u9762\u6765\u8868\u793a\u53cc\u5f15\u53f7\u5b57\u7b26\uff0c\u5355\u5f15\u53f7\u53ef\u4ee5\u653e\u5728\u53cc\u5f15\u53f7\u91cc\u9762\u8868\u793a\u5355\u5f15\u53f7\u5b57\u7b26<\/p>\n\n\n\n<p>String\u7684\u4e00\u4e9b\u6210\u5458\u51fd\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>String.charAt<\/strong><\/li><li><strong>String.concat<\/strong><\/li><li><strong>String.includes<\/strong><\/li><li><strong>String.endsWith<\/strong><\/li><li><strong>String.indexOf<\/strong><\/li><li><strong>String.lastIndexOf<\/strong><\/li><li><strong>String.match<\/strong><br>\u5728\u6307\u5b9a\u5b57\u7b26\u4e32\u4e2d\u641c\u7d22\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u8fd4\u56de\u4e00\u4e2aObject\uff0c\u8be5Object\u5177\u6709\u4e09\u4e2a\u5c5e\u6027\uff1a\u641c\u7d22\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u8be5\u6b63\u5219\u8868\u8fbe\u5f0f\u5728\u8be5\u5b57\u7b26\u4e32\u5339\u914d\u4f4d\u7f6e\u7684\u7d22\u5f15\uff0c\u8be5\u5b57\u7b26\u4e32\u3002<\/li><li><strong>String.search<\/strong><br>\u540c<em>match<\/em>\uff0c\u4f46\u662f\u53ea\u8fd4\u56de\u5339\u914d\u7684\u7d22\u5f15\u3002<\/li><li><strong>Strng.normalize<\/strong><br>\u6ca1\u770b\u61c2\u8fd9\u4e2a\u51fd\u6570\u5728\u5e72\u5565~<\/li><li><strong>String.repeat<\/strong><\/li><li><strong>String.replace<\/strong><\/li><li><strong>String.slice<\/strong><br>\u4e0e<strong>substring<\/strong>\u7c7b\u4f3c\uff0c\u4f46\u662f\u53ef\u4ee5\u63a5\u6536\u8d1f\u6570(\u4ee5\u5b57\u7b26\u4e32\u957f\u5ea6\u4e3a\u6a21\u6765\u8fdb\u884c\u8fd0\u7b97)\u4f5c\u4e3a\u53c2\u6570\u3002<\/li><li><strong>String.split<\/strong><\/li><li><strong>String.startsWith<\/strong><\/li><li><strong>String.substr<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">substr([start[, length]])\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>String.substring<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">substring([start[, end]])\n<\/code><\/pre>\n\n\n\n<p><em>substring<\/em>\u65b9\u6cd5\u4f1a\u6bd4\u8f83<em>start<\/em>\u548c<em>end<\/em>\u5927\u5c0f\uff0c\u9009\u62e9\u8f83\u5c0f\u7684\u4e3a\u8d77\u70b9\uff0c\u8f83\u5927\u7684\u4e3a\u7ec8\u70b9(\u4e0d\u542b)\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>String.toLowerCase<\/strong><\/li><li><strong>String.toUpperCase<\/strong><\/li><li><strong>String.trim<\/strong><\/li><li><strong>String.trimLeft<\/strong><\/li><li><strong>String.trimRight<\/strong><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86\"><span class=\"ez-toc-section\" id=\"%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86\"><\/span>\u5f02\u5e38\u5904\u7406<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5f02\u5e38\u5904\u7406\u7684\u4e00\u822c\u6a21\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">try {\n} catch (e) {\n} finally {\n}\n<\/code><\/pre>\n\n\n\n<p>\u629b\u51fa\u5f02\u5e38\u7684\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u76f4\u63a5<code>throw vale<\/code><\/li><li><code>throw new Error(customError)<\/code>\uff0c\u8fd9\u4e2a<code>customError<\/code>\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u901a\u8fc7<em>catch<\/em>\u6355\u83b7\u8fd9\u4e2a\u5f02\u5e38\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<em>message<\/em>\u5c5e\u6027\u8bbf\u95ee\u8fd9\u4e2a\u5b57\u7b26\u4e32\u3002<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-4-create-a-rectangle-object\"><span class=\"ez-toc-section\" id=\"Day_4_Create_a_Rectangle_Object\"><\/span>Day 4: Create a Rectangle Object<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>JavaScript\u4e2d\u7684\u5bf9\u8c61\u5c31\u662f\u4e00\u5806\u5c5e\u6027\u7684\u96c6\u5408\uff0c\u5c5e\u6027\u7684\u540d\u5b57\u751a\u81f3\u53ef\u4ee5\u662f\u7a7a\u5b57\u7b26\u4e32\u3002<\/li><li>\u8bbf\u95ee\u5c5e\u6027\u7684\u65b9\u5f0f\u6709\u4e24\u79cd\uff1a<ul><li><code>objectName.propertyName<\/code><\/li><li><code>objectName['propertyName']<\/code><\/li><\/ul><\/li><li>\u6784\u9020\u5bf9\u8c61\u7684\u65b9\u5f0f\u4e5f\u6709\u4e24\u79cd\uff1a<ul><li>\u4f7f\u7528Object\u7684\u521d\u59cb\u6784\u9020\u51fd\u6570<br>\u5305\u62ec\u50cfmap\u4e00\u6837\u6784\u9020(<code>{property1:xxx,property2:xxx,property3:xxx}<\/code>)\u3001\u4f7f\u7528<code>new Object()<\/code>\u58f0\u660e\u5bf9\u8c61\u7136\u540e\u4e3a\u5c5e\u6027\u8d4b\u503c\u3001\u4f7f\u7528<code>Object.create<\/code>\u51fd\u6570\u6784\u9020<\/li><li>\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684\u6784\u9020\u51fd\u6570\u914d\u5408<em>new<\/em>\u8868\u8fbe\u5f0f<\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">function Actor(firstName, lastName, Age) {\n    this.firstName = firstName;\n    this.lastName = lastName;\n    this.Age = Age;\n}\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-4-classes\"><span class=\"ez-toc-section\" id=\"Day_4_Classes\"><\/span>Day 4: Classes<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Functional Classes<\/strong><br>\u53ef\u4ee5\u7528\u51fd\u6570\u6765\u6a21\u62df\u7c7b\uff1a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">'use strict';\n\nfunction Fruit (type) {\n    this.type = type;\n    this.color = 'unknown';\n    this.getInformation = getFruitInformation;\n}\n\nfunction getFruitInformation() {\n    return 'This ' + this.type + ' is ' + this.color + '.';\n}\n\nlet lime = new Fruit('Mexican lime');\nconsole.log(lime.getInformation());\n\nlime.color = 'green';\nconsole.log(lime.getInformation());\n<\/code><\/pre>\n\n\n\n<p>\u50cf\u4e0a\u9762\u4ee3\u7801\u4e2d\u7684<em>getInformation<\/em>\u51fd\u6570\u4e5f\u53ef\u4ee5\u7528\u533f\u540d\u51fd\u6570\u7684\u65b9\u5f0f\u76f4\u63a5\u5b9a\u4e49\u5728\u51fd\u6570\u4f53\u5185\uff0c\u4f46\u662f\u8fd9\u6837\u4f1a\u5bfc\u81f4\u6bcf\u5b9a\u4e49\u4e00\u4e2a<em>Fruit<\/em>\u5bf9\u8c61\u65f6\u90fd\u4f1a\u5b9a\u4e49\u4e00\u4e2a\u65b0\u7684\u533f\u540d\u51fd\u6570\u3002JavaScript\u4e2d\u7684\u6bcf\u4e2a\u51fd\u6570\u90fd\u6709\u4e00\u4e2a<em>Prototype<\/em>\u5c5e\u6027\uff0c\u66f4\u597d\u7684\u505a\u6cd5\u662f\u5c06<em>getInfomation<\/em>\u51fd\u6570\u4f5c\u4e3a\u5c5e\u6027\u52a0\u5165\u5230<em>Prototype<\/em>\u5c5e\u6027\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">'use strict';\n\nfunction Fruit (type) {\n    this.type = type;\n    this.color = 'unknown';\n}\n\nFruit.prototype.getInformation = function() {\n    return 'This ' + this.type + ' is ' + this.color + '.';\n}\n\nlet lime = new Fruit('Mexican lime');\nconsole.log(lime.getInformation());\n\nlime.color = 'green';\nconsole.log(lime.getInformation());\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Classes<strong>ECMAScript6<\/strong>\u63d0\u4f9b\u4e86\u7c7b\u7684\u8bed\u6cd5\u7cd6\uff0c\u65b9\u4fbf\u6309\u7167\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\u7f16\u7a0b\u3002<ul><li>\u6784\u9020\u51fd\u6570<em>constructor<\/em><\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">class Polygon {\n    constructor(height, width) {\n        this.height = height;\n        this.width = width;\n    }\n}\n\nlet p = new Polygon(1, 2);\nconsole.log('Polygon p:', p);\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Class Expressions<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">let Polygon = class {\n    constructor(height, width) {\n        this.height = height;\n        this.width = width;\n    }\n};\n\nconsole.log('Polygon:', Polygon);\nlet p = new Polygon(1, 2);\nconsole.log('p:', p);\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">let Polygon = class Polygon {\n    constructor(height, width) {\n        this.height = height;\n        this.width = width;\n    }\n};\n\nconsole.log('Polygon:', Polygon);\nlet p = new Polygon(1, 2);\nconsole.log('p:', p);\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Prototype Methods\u5728\u7c7b\u7684\u5b9a\u4e49\u4e2d\u76f4\u63a5\u5b9e\u73b0\u7684\u65b9\u6cd5\u662f<strong>Prototype Methods<\/strong>\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">'use strict';\n\nclass Polygon {\n    constructor(height, width) {\n        this.height = height;\n        this.width = width;\n    }\n    getArea() {\n        return this.height * this.width;\n    }\n}\n\nconst square = new Polygon(10, 10);\n\nconsole.log(square.getArea());\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Static Methods<br>\u5982\u679c\u51fd\u6570\u58f0\u660e\u65f6\u7528\u4e86<em>static<\/em>\u5173\u952e\u5b57\uff0c\u90a3\u4e48\u53ea\u80fd\u901a\u8fc7\u7c7b\u6765\u8c03\u7528\u8be5\u65b9\u6cd5\uff0c\u4e0d\u80fd\u901a\u8fc7\u8be5\u7c7b\u7684\u5b9e\u4f8b\u6765\u8c03\u7528\u8be5\u65b9\u6cd5\u3002<\/li><li>\u7ee7\u627f<br>\u901a\u8fc7<em>extends<\/em>\u5173\u952e\u5b57\u5b9e\u73b0\u7c7b\u7684\u7ee7\u627f\uff0c\u5b50\u7c7b\u901a\u8fc7<em>super<\/em>\u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u51fd\u6570\u548c\u7236\u7c7b\u4e2d\u5b9a\u4e49\u7684\u540c\u540d\u51fd\u6570\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">'use strict';\n\nclass Animal {\n    constructor(name) {\n        this.animalType = 'Animal'\n        this.name = name;\n    }\n    type() {\n        console.log(this.name, 'is type', this.animalType);\n    }\n    speak() {\n        console.log(this.name, 'speaks.');\n    }\n}\n\nclass Dog extends Animal {\n    constructor(name, collarColor) {\n        super(name);\n        this.animalType = 'Dog';\n        this.collarColor = collarColor;\n    }\n    speak() {\n        console.log(this.name, 'barks.');\n    }\n    collar() {\n        console.log(this.name, 'has a', this.collarColor, 'collar.');\n    }\n}\n\nlet spot = new Dog('Spot', 'red');\nspot.type();\nspot.speak();\nspot.collar();\n\n<em>\/\/ Because the Animal constructor only expects one argument,<\/em>\n<em>\/\/ only the first value passed to it is used<\/em>\nspot = new Animal('Spot', 'white');\nspot.type();\nspot.speak();\ntry {\n    spot.collar();\n}\ncatch (exception) {\n    console.log(exception.name + ': ' + exception.message\n    + ' (collar is a method of Dog, not Animal).');\n}\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-5-template-literals\"><span class=\"ez-toc-section\" id=\"Day_5_Template_Literals\"><\/span>Day 5: Template Literals<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>\u53ef\u4ee5\u4f7f\u7528**`**\u6765\u8868\u793a\u8de8\u8d8a\u591a\u884c\u7684\u5b57\u7b26\u4e32\u3002<\/li><li><strong>expression interpolation<\/strong><br>\u53ef\u4ee5\u7528**${expression}**\u7684\u65b9\u5f0f\u5728template literals\u4e2d\u52a0\u5165\u8868\u8fbe\u5f0f\u6216\u8005\u76f4\u63a5\u4f7f\u7528\u5b57\u7b26\u4e32\u4e0e\u8868\u8fbe\u5f0f\u76f8\u52a0\u7684\u65b9\u5f0f\u3002<\/li><li><strong>Tagged Template Literals<\/strong><br>\u53ef\u4ee5\u901a\u8fc7\u5728\u6bcf\u4e2a**${expression}<strong>\u524d\u9762\u52a0\u4e00\u4e2a\u540d\u5b57\u7684\u65b9\u5f0f\u5f62\u6210<\/strong>Tagged Template Literals**\uff1a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">var a = 5;\nvar b = 10;\n\nfunction foo(strings, ...values) {\n    console.log(\".\" + strings[0] + \".\");\n    console.log(\".\" + strings[1] + \".\");\n    console.log(\".\" + strings[2] + \".\");\n    console.log(\".\" + strings[3] + \".\");\n    console.log(values[0]);\n    console.log(values[1]);\n    console.log(values[2]);\n}\n\nfoo`Sum ${a + b}\nProduct ${a * b}\nDivision ${b \/ a}`;\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-5-arrow-functions\"><span class=\"ez-toc-section\" id=\"Day_5_Arrow_Functions\"><\/span>Day 5: Arrow Functions<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>\u8fd9\u4e2a\u6559\u7a0b\u91cc\u8bb2\u7684<strong>Arrow Functions<\/strong>\u5927\u6982\u5c31\u662f<strong>lambda\u8868\u8fbe\u5f0f<\/strong>\uff1f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">(parameter) =&gt; {statements}\nparameter =&gt; {statements}\nparameter =&gt; expression\nparameter =&gt; {return expression}\n\n(param1, param2, ..., paramN) =&gt; {statements}\n(param1, param2, ..., paramN) =&gt; expression\n(param1, param2, ..., paramN) =&gt; {return expression}\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"day-7-regular-expressions\"><span class=\"ez-toc-section\" id=\"Day_7_Regular_Expressions\"><\/span>Day 7: Regular Expressions<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>\u521b\u5efaRegular Expression Literal\uff1a<\/li><\/ul>\n\n\n\n<p>\u53ef\u4ee5\u901a\u8fc7\u628a\u6b63\u5219\u8868\u8fbe\u5f0f\u7684pattern\u653e\u5728\u4e24\u4e2a&#8217;\/&#8217;\u4e2d\u95f4\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">   const re = \/ab+c\/;\n<\/code><\/pre>\n\n\n\n<p>\u6216\u8005\u76f4\u63a5\u58f0\u660e\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u5bf9\u8c61\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">   const re = new RegExp('ab+c'); \t\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684flag\u53c2\u6570\uff1a&nbsp;<code>\/pattern\/flags<\/code>\u548c<code>new RegExp(pattern[, flags])<\/code>\u4e24\u79cd\u65b9\u5f0f\u90fd\u63d0\u4f9b\u4e86\u4e00\u4e2a\u53ef\u9009\u7684flags\u53c2\u6570\uff0cflags\u53ef\u4ee5\u662f\u4ee5\u4e0b\u53c2\u6570\u7684\u7ec4\u5408\uff1a<\/li><li><strong>g<\/strong>\uff1a\u5168\u5c40\u641c\u7d22\uff1b<\/li><li><strong>i<\/strong>\uff1a\u5ffd\u7565\u5927\u5c0f\u5199\uff1b<\/li><li><strong>m<\/strong>\uff1a\u8de8\u884c\u641c\u7d22\uff1b<\/li><li><strong>u<\/strong>\uff1a<em>Treat pattern as a sequence of unicode code points<\/em>\uff1b<\/li><li><strong>y<\/strong>\uff1asticky\uff1b<\/li><li>\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u56de\u6eaf\u5f15\u7528 \u95ee\u9898\uff1a\u5339\u914d\u540c\u4e00\u4e2a\u5143\u97f3\u5b57\u6bcd\u5f00\u5934\u548c\u7ed3\u5c3e\u7684\u5b57\u7b26\u4e32\u3002\u9700\u8981\u4f7f\u7528\u56de\u6eaf\u5f15\u7528(backreference)\u6765\u5f15\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u524d\u9762\u90e8\u5206\u5339\u914d\u7684\u7ed3\u679c(\u6355\u83b7\u7ec4, capture groups)\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">function regexVar() {\n    <em>\/*\n     * Declare a RegExp object variable named 're'\n     * It must match a string that starts and ends with the same vowel (i.e., {a, e, i, o, u})\n     *\/<\/em>\n    const re = \/^([aeiou]).*\\1$\/;\n    \n    <em>\/*\n     * Do not remove the return statement\n     *\/<\/em>\n    return re;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hackerrank\u7f51\u7ad9\u4e0a\u6709\u4e00\u4e2a10\u5929\u7684js\u6559\u7a0b\uff0c\u4f5c\u4e3a\u4e00\u4e2a\u5199js\u7684\u534a\u540a\u5b50\u6b63\u597d\u53ef\u4ee5\u8fc7\u4e00\u904d\u6765\u5de9\u56fa\u4e0b\u81ea\u5df1\u7684js\u6280\u80fd\u3002 Day 0: Hello World JavaScript\u7a0b\u5e8f\u662f\u4f7f\u7528Unicode\u5b57\u7b26\u96c6&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[106],"class_list":["post-930","post","type-post","status-publish","format-standard","hentry","category-10","tag-js"],"_links":{"self":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=930"}],"version-history":[{"count":2,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/930\/revisions"}],"predecessor-version":[{"id":932,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/930\/revisions\/932"}],"wp:attachment":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}