1. Q1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    function doSomething(){
    for(var i=0;i<4;i++){
    var value = 100;
    str += ',' + (value + i);
    }
    }
    var value = 1, str = value;
    doSomething();
    str += value;
    console.log(str)
  1. Q2
    1
    2
    3
    4
    5
    6
    var a = [];
    a[0] = 0;
    a[1] = 1;
    a[4] = 4;
    console.log(a.length);
    console.log(a[3])
  1. Q3

    1
    2
    3
    4
    var a = [5,6];
    var b = a;
    b[0] = 'hello';
    console.log(a[0])
  2. Q4

    1
    2
    3
    4
    console.log(undefined || 1);
    console.log(null || NaN);
    console.log(0 && 1);
    console.log(0 && 1 || 0);
  1. Q5
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    function Foo(){
    var i = 0;
    return function(){
    console.log(i++);
    }
    }
    var f1 = Foo(),f2 = Foo();
    f1();
    f2();
    f2();
    console.log(i)
  1. Q6

    1
    2
    3
    4
    5
    6
    7
    var num = 1;
    var fun = function(){
    console.log(num);
    var num = 2;
    console.log(num);
    }
    fun();
  2. Q7

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    var a = [];
    for(var i = 0; i<10;i++){
    a[i] = function(){
    console.log(i)
    }
    };
    a[6]();
    var b = [];
    for(let j=0;j<10;j++){
    b[j] = function(){
    console.log(j)
    }
    };
    b[6]();
  3. 8Q

    1
    2
    3
    4
    5
    6
    7
    8
    9
    let[,,third] = ['foo','bar','baz'];
    console.log(third)

    let[head, ...tail] = [1,2,3,4];
    console.log(tail)

    let[x,y='b'] = ['a',undefined];
    console.log(y);
    let{foo:baz} = {foo:'aaa',bar:'bbb'}
  1. 9Q
    1
    2
    3
    4
    5
    6
    for(var i=0;i<5;i++){
    setTimeout(function(){
    console.log(new Date,i)
    },1000)
    }
    console.log(new Date,i)
1
2
3
4
5
6
7
8
9
10
11
var name = 'window';
var obj = {
name: 'obj',
getName: function(){
console.log(this.name);
return function(){
console.log(this.name)
}
}
}
obj.getName()()