1.

var a = 10,
    b = 11,
    c = 12;
function test(a) {
    a = 1;
    var b = 2;
    c = 3;
}
test(10);
console.log(a, b, c);
Copy the code

2,

var a = 4;
function b(x, y, a) {
    console.log(a);
    arguments[2] = 10;
    console.log(a);
}
a = b(1, 2, 3);
console.log(a);
Copy the code

3. We need to understand at what stage the mapping mechanism is established (only at parameter assignment stage)

function fn(x, y) { /! * * EC(FN) * Scope chain :<EC(FN),EC(G)> {0:10,length:1} * assign :x=10 y=undefined * "mapping" x->arguments[0] * / let arg = arguments; x = 100; console.log(arg[0]); //=>100 arg[1] = 200; console.log(y); //=>undefined } fn(10);Copy the code

4,

var a = 9;
function fn() {
    a = 0;
    return function (b) {
        return b + a++;
    }
}
var f = fn();
console.log(f(5));
console.log(fn()(5));
console.log(f(5));
console.log(a);
Copy the code

5,

var test = (function (i) {
    return function () {
        alert(i *= 2);
    }
})(2);
test(5);
Copy the code

6,

var x = 4;
function func() {
    return function(y) {
        console.log(y + (--x));
    }
}
var f = func(5);
f(6);
func(7)(8);
f(9);
console.log(x);
Copy the code

7,

 var x = 5,
    y = 6;
function func() {
    x += y;
    func = function (y) {
        console.log(y + (--x));
    };
    console.log(x, y);
}
func(4);
func(3);
console.log(x, y);
Copy the code

Eight,

function fun(n, o) { console.log(o); return { fun: function (m) { return fun(m, n); }}; } var c = fun(0).fun(1); c.fun(2); c.fun(3);Copy the code