摘要: 为了方便创建复杂灵活的字符串,用到了重音符:‘ `` ’(backtick),和 ‘ ${ } ’。 const person = { name: "Zodiac Hasbro", age: 56 }; const greeting = `Hello, my name is ${person.nam 阅读全文
posted @ 2022-09-14 21:25 枭二熊 阅读(816) 评论(0) 推荐(0) 编辑
摘要: 析构赋值——对象篇 《一》使用析构赋值从对象中提取相应的值赋给相同变量名的变量:const { today, tomorrow }=LOCAL_FORECAST; 《二》使用析构赋值从对象中提取相应的值赋给相同变量名的变量,然后将变量名更改,使其与对象里的变量名不相同:const { today:n 阅读全文
posted @ 2022-09-14 10:34 枭二熊 阅读(252) 评论(0) 推荐(0) 编辑
摘要: 《剩余参数‘...’》 In order to help us create more flexible functions, ES6 introduces the rest parameter for function parameters. 为了帮助我们创建更灵活的函数,ES6为函数参数引入了r 阅读全文
posted @ 2022-09-13 20:07 枭二熊 阅读(766) 评论(0) 推荐(0) 编辑
摘要: ES5(JS)中定义匿名函数: const myFunc = function() { const myVar = "value"; return myVar; } ES6中定义匿名函数: const myFunc = () => { const myVar = "value"; return my 阅读全文
posted @ 2022-09-12 20:52 枭二熊 阅读(57) 评论(0) 推荐(0) 编辑
摘要: const Some developers prefer to assign all their variables using const by default, unless they know they will need to reassign the value. Only in that 阅读全文
posted @ 2022-09-12 16:23 枭二熊 阅读(216) 评论(0) 推荐(0) 编辑
摘要: When you declare a variable with the var keyword, it is declared globally, or locally if declared inside a function. 当使用var关键字声明变量时,它是全局声明的(在循环语句中声明也是 阅读全文
posted @ 2022-09-12 11:16 枭二熊 阅读(79) 评论(0) 推荐(0) 编辑
摘要: 《一》使用递归函数时,用push给数组增加新值: 注: FIFO先进先出:push+pop或者unshift+shift。 LIFO后进先出:push+shift或者unshift+pop。 一般使用递归是用来代替for循环。 function countup(n) { if (n < 1) { r 阅读全文
posted @ 2022-09-11 12:31 枭二熊 阅读(1237) 评论(0) 推荐(0) 编辑
摘要: You are given an object literal representing a part of your musical album collection. Each album has a unique id number as its key and several other p 阅读全文
posted @ 2022-09-10 16:56 枭二熊 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 将“return 'No such contact';”放在for循环里面: 注:下面例子中的contacts是一个数组,里面存放的是JS的对象。 function lookUpProfile(name, prop) { for (var i=0; i<contacts.length; i++) { 阅读全文
posted @ 2022-09-10 15:58 枭二熊 阅读(40) 评论(0) 推荐(0) 编辑
摘要: 求数组前n个数的乘积: function multiply(arr, n) { if (n <= 0) { return 1; //1乘任何数都不会有加成,对结果没有影响。 } else { return multiply(arr, n - 1) * arr[n - 1]; } } 求数组前n个数的 阅读全文
posted @ 2022-09-09 21:13 枭二熊 阅读(28) 评论(0) 推荐(0) 编辑