重学 ES6
文章目录
块级作用域变量
let word1 = 'hello'
const word2 = 'world'
let 用于声明变量 const 用于声明常量,常量一旦声明便无法更改
使用 let 和 const 声明的变量是有块级作用域(函数体,判断体,循环体等)
因此建议使用 es6 语法中 let const 来定义变量
模板字符串代替字符串拼接
const a = 'hello'
const b = 'world'
// in ES5
const c = a + ' ' + b
// in ES6 used 模板字符串
const d = `${a} ${b}`
padStart()、padEnd()
新的字串填充方法,可以从start位置或是end位置,开始填充到指定数字长度,被填充的内容为第二个参数。
let astring = 'moment'
console.log(astring.padStart(10,'m'))
// 'mmmmmoment'
console.log('abc'.padStart(10, "foo"))
// "foofoofabc"
console.log('abc'.padEnd(10, "f