ECMAScript 6复习<一>

1.let和const命令:

let不存在变量提升

暂时性死区

let在相同作用域内不允许重复声明

2.块级作用域:

3.全局对象的属性:

var a = 1;
window.a   // 1
let b = 1;
window.b  //undefined

var声明的是全局对象,b由let声明的不是全局对象的属性。

4.变量的解构赋值:

var [a, b, c] = [1, 2, 3];

默认值:

var [foo = true] = [];  // foo = true
[x, y = 'a'] = ['a'];   // x='a', y = 'b'
[x, y = 'b'] = ['a', undefined];   // x = 'a', y = 'b'

对象的解构赋值:

var { foo, bar } = {foo: 'aaa', bar: 'bbb'}
foo  // 'aaa'
bar  // 'bbb'

 字符串的解构赋值:

const [a, b, c, d, e] = 'hello';
a  //'h'
b  //'e'

let {length: len} = 'hello';
len  // 5

函数参数的结构赋值:

function add([x, y]) {
   return x + y;
}

add([1, 2]);   // 3

圆括号问题:

1> 变量声明语句中,不能带圆括号;

2> 函数参数中,模式不能带有圆括号;

3> 赋值语句中,不能将整个模式或嵌套模式中一层放在圆括号之中。

一个字符串是否包含在另一个字符串中:

includes()

startsWith()

endsWith()

repeat()返回新的字符串,将原字符串重复n次。

'x'.repeat(3)   // 'xxx'
'hello'.repeat(2)   //'hellohello'

padStart()头部补全

padEnd()尾部补全

'x'.padStart(5, 'ab')   // 'ababx'

'x'.padEnd(5, 'ab')    // 'xabab'

模板字符串:

用反引号`标识。

`In javascript '
' is a line-feed.`
`heelo ${name}, how are you ${time}.`

正则的扩展:

  

原文地址:https://www.cnblogs.com/pengsi/p/8529763.html