数美(sm)面经

1、

console.log(1 && 0)
console.log(0 && 1)

2、

window.val = 1;
var json = {
    val: 10,
    dbl: function(){
        this.val *= 2;  
  }
};
json.dbl();
var dbl = json.dbl;
dbl();
json.dbl.call(window);
alert(window.val + json.val);

3、

var name = 'Shumei';
(function(){
    if(typeof  name === 'undefined'){
         var name = 'SM';
         console.log('Hello' + name);
    } else {
         console.log('Hello' + name);
    } 
}) ();

4、

function Test(name, age){
    this.name = name;
    if(age!= undefined){
          this.age = age;
​
    }
}
​
Test.prototype = {
    name: "SM",
    age: 18
};
​
var instance = new Test();
console.log(instance.name);
console.log(instance.age);
console.log(instance.constructor);

5、

console.log(null == undefined)
console.log(Boolean("false"))
console.log({} == 0)
console.log([] == 0)

6、

var a1 = [1,2];
var a2 = a1;
a1[0] = a2[1];
a2.push(3);

console.log(a1);
console.log(a2);

7、

setTimeout(function(){
   console.log(1)
}, 0);

new Promise(function(resolve, reject){
    var i = 0;
    console.log(2);
    while(i<100){
         i ++ ;
         i == 1 && resolve();
    }
    console.log(3);
}).then(function(){
    console.log(4)
});

console.log(5);

 

posted @ 2020-04-24 20:59  nini123123  阅读(221)  评论(0编辑  收藏  举报