Check the gaps. . .

1. What is the relationship between es6 and js?

es6 is also called ECMA Script specification, js is the realization of this specification

let a = 3
a = 44
console.log(a) // 44

2. const defines basic data types that cannot be changed, and reference data types do not have this restriction

3. The key of the Map can be any type, and the key of the object can only be a string

4. Arrow function shorthand

const test = v => v

Is equivalent to:

function test (v) {
  return v
}

Arrow function does not write return

5. A question

var length = 100
function fn () {
  console.log(this.length)
}
var obj = {
  length: 10,
  fn2: function (fn) {
    fn()
    arguments[0]()
  }
}
obj.fn2(fn, 1)

First, obj.fn2 executes fn2. The function fn is passed as a parameter to another function, a typical closure, this refers to the place where the function is defined, so this.length is 100, arguments[0](), First of all arguments[0] refers to the first parameter passed in, which is fn. When fn is called, what does this point to?

obj.id and obj['id'] are actually equal, so in layman's terms, arguments[0] is also equivalent to arguments.0 (but it cannot be used in this way),

function fn2 () {
  console.log(this)
}
var arr = [fn2, 1, 2]
arr[0]()

result:

[ƒ, 1, 2] // 是这个arr

So at this time this points to arguments, and arguments.length is the number of parameters passed in, so it is 2

100
2

6. 

a = 1
var a;
console.log(a) // 1

a is not assigned and has no effect

7. 

var a = 10
    function fn () {
      var b = 2 * a;
      var a = 20;
      var c = a + 1;
      console.log(b)
      console.log(c)
    }
    fn()

First of all, b = 2 * a. To find a, first check whether there is inside the function. If you don’t find it outside the function, a is defined inside the function, but it is defined below it, so at this time a is undefined. Then b = NaN, c = a + 1, before this line of code, a has defined 20, then c is 21

NaN
21

 

Guess you like

Origin blog.csdn.net/Luckyzhoufangbing/article/details/108619812