.

If you can answer these questions quickly and accurately, skip them

First sacrifice out of the big kill recruit: bracket a bit of oil into making clothes called allele naked jumping clothing exhibition zhao

Sentence: bracket oil, adjust one, do clothes; Call allele, naked jump, fu zhan Zhao

You can imagine a scenario to assist memory: have a clothing store boss called exhibition zhao, we will go to his house to make clothes, then around a little bit of oil, the price to ten percent, exhibition zhao is very uncomfortable, we equipotential, not equal to do, show a naked dance (because our clothes are still not ready, now is not wearing clothes yo) to persuade the exhibition zhao

explain

Description: the brackets

Click: Member Access

Oil: new

Call: function call

One: unary operator

Multiply, divide, add, subtract

Make clothes: move by position left and right

It’s called: the comparison operator (greater than less than)

Such as: equal to

Bit: bit and or

Bare: Logical and or

Jump: conditional operator

Clothing: assignment

Expansion: Expansion operator

Zhao: a comma

1. What is r equal to

function F() {
  this.a = 1
  this.f = function() {
    this.a = 3
  }
}

F.f = function() {
  this.a = 2
}

var r = new F.f()

Copy the code
  • A. {a: 2}
  • B. {a: 1, f: ƒ}
  • C. {a: 3}
The answer

Answer: A,

First F.f, then new… (a)

2. What does STR equal

var str = "Hello" + true ? "World" : "JS";
Copy the code
  • A. “World”
  • B. “Hello World”
  • C. “Hello JS”
The answer

Answer: A,

+ takes precedence over… ? . :…

What is a equal to

function myFunc () {
    var x = 0;
    var y = 1
    return (x,y);
}

var a = myFunc ()
Copy the code
  • A. (0, 1)
  • B. 0
  • C. 1
  • D. [0, 1]
The answer

Answer: C

The comma operator evaluates each of its operands (from left to right) and returns the value of the last one.

4. Print what

var obj = {
    a: {
        f: function(){
            return function(config){
				console.log(this)}; }}};var type = "a";
var config = {};
new obj[type].f()(config);

Copy the code
  • A. obj
  • B. a
  • C. f
  • D. Window
The answer

Answer: D

The js engine will parse the code into (new Provider [type].Get ()) returns an anonymous function and is executed in the Window environment, so this refers to Window

5. What is output

var x = 1
console.log(x)
console.log(x++)
console.log(++x)
Copy the code
  • A. 1 2 3
  • B. 1 1 3
  • C. 1 1 1
  • D. 1 2 2
The answer

Answer: B

X ++ is using x first and then adding 1, plus ++x is adding 1 first and then using x

6. What is output

var x = 1
console.log(x+++1)
console.log(++x+1)
Copy the code
  • A. 2 4
  • B. 3 4
  • C. 1 2
The answer

Answer: A,

X ++ is using x first and then adding 1, plus ++x is adding 1 first and then using x

7. What is output

var x = 1
console.log(! x++)var x = 1
console.log(! ++x)Copy the code
  • A. false false
  • B. false true
  • C. true false
  • D. true true
The answer

Answer: A,

The first console, x++, takes precedence over! , so the equivalent of! One is false

The second console,! It’s in the same order as ++x, and it’s calculated from right to left, which is the same thing as! 2 are false

8. What is z

var x = 1
var y = 10
var z = y+++x
Copy the code
  • A. 11
  • B. 12
  • C. 10
  • D. 1
The answer

Answer: A,

Is equivalent to (y++) + x

9. What is output

console.log(void 1 + 1)
Copy the code
  • A. NaN
  • B. undefined
  • C. null
  • D. 2
The answer

Answer: A,

Void takes precedence over +, so it equals (void 1) + 1, and void 1 equals undefined, so the result is NaN

10. What is output

var x = 2
console.log(x*2六四运动3)
Copy the code
  • A. 16
  • B. 64
  • C. NaN
  • D. TypeError
The answer

Answer: A,

** priority above * is equivalent to x * (2 ** 3)

11. What is output

var x = 8
console.log(x>>2+1)
Copy the code
  • A. 3
  • B. 1
  • C. 33
  • D. NaN
The answer

Answer: B

  • A priority higher than >> equals x >>3

12. What is output

var x = 8
console.log(x+=x>>2)
Copy the code
  • A. 4
  • B. 10
  • C. 8
  • D. 16
The answer

Answer: B

> Priority higher than += equals x += 2

13. What are the execution steps

0| |!0&&1

Copy the code
  • A. 0||(! && (0 1))
  • B. 0||((! 0) && 1)
  • C. (0||(! && 1 0))
The answer

Answer: B

! Highest priority first! 0

&& priority than | |

14. What is output

var o ={
	ab: 1
}
console.log('a' + 'b' in o)
Copy the code
  • A. true
  • B. ‘afalse’
  • C. ‘atrue’
  • D. false
The answer

Answer: A,

So let’s do a’ + ‘b’.

15. What is output

function * f() {
  var x = 1
  var y = yield x + 1
  console.log(y)
  var z = yield y + 1 
  console.log(z)
}

var g = f()
console.log(g.next(10).value)
console.log(g.next(100).value)
console.log(g.next(1000).value)
Copy the code
  • A. 2 100 101 1000 undefined
  • B. 2 2 3 3 undefined
  • C. 2 10 11 100 1000
  • D. 2 10 11 100 undefined
The answer

Answer: A,

Generator functions are called by a pair of parentheses after the function name, just like normal functions. The difference is that after a Generator function is called, the function does not execute, and instead of returning the result of the function’s run, it returns a pointer Object to the internal state, the Iterator Object described in the previous chapter.

Next, you must call the next method on the traverser object to move the pointer to the next state. That is, each time the next method is called, the internal pointer is executed from the head of the function or where it stopped last, until the next yield expression (or return statement) is encountered.

The next method can take one argument, which is treated as the return value of the previous yield expression

So the 10 of console.log(g.ext (10).value) is useless

16. What is output

function f() {
    let x = y = 1
}
f()
console.log(x, y)
Copy the code
  • A. 1 1
  • B. undefined 1
  • C. undefined undefined
  • D. 1 undefined
The answer

Answer: B

The assignment operators are ordered from right to left, so y=1 is executed first. Since y is not defined, y is a global variable here

And then you assign y to x, but x is a local variable and not accessible outside of the function

So the answer is undefined 1

17. What is output

const colorConfig = {
  red: true.blue: false.green: true.black: true.yellow: false,}const colors = ["pink"."red"."blue"]

console.log(colorConfig.colors[1])

Copy the code
  • A. true
  • B. false
  • C. undefined
  • D. TypeError
The answer

Answer: D

From left to right

18. What is output

const str = "hello";
console.log(!typeof str === "object");
console.log(!typeof str === "string");


Copy the code
  • A. false true
  • B. false false
  • C. true true
  • D. true false
The answer

Answer: B

Typeof STR returns “string”. So! Typeof name returns a Boolean value of false.

False === “object” and false === “string” both return false.

19. What is output

var a = {n: 1};
var b = a;
a.x = a = {n: 2};

console.log(a.x) 	
console.log(b.x)

Copy the code
The answer

The answer:

undefined

{n:2}

A.x = a = {2} n: will perform a.x, here is a {n: 1}, b = = = this time become a {n: 1, x: undefined} after transformed from right to left to perform a 2} {n:, b becomes a {n: 1, x: {n: 2}}

A ={n: 2}, b={n:1,x:{n:2}}

Summary table of priorities

Recall the memory secret: a little oil into a dress called allele naked jumping clothing exhibition zhao

explain

Description: the brackets

Click: Member Access

Oil: new

Call: function call

One: unary operator

Multiply, divide, add, subtract

Make clothes: move by position left and right

It’s called: the comparison operator (greater than less than)

Such as: equal to

Bit: bit and or

Bare: Logical and or

Jump: conditional operator

Clothing: assignment

Expansion: Expansion operator

Zhao: a comma

reference

  • Introduction to ES6

Personal blog

Github.com/abc-club/fr…