js基础面试题 看似简单也易出错

1.
alert(a)
a()
var a=3
function a(){alert(10)}
alert(a)
a=6
a()



===》
function a(){alert(10)}  //变量提升a方法
10  第二步执行a 输出10
3  a重新赋值 3
a is not a function  赋值a=6 不是一个function

2.
var lili={age:18};
    (function () {
      var xiaoming=lili;
      xiaoming.age=22;
      console.log(xiaoming.age);
      console.log(lili.age)
    } ) ()
    console.log(lili.age);
    console.log(xiaoming.age)
===》 22  22  22  

3.
function A() {
  this.name='a'
this.color=['green','yellow']
}
function B(){}
B.prototype=new A()
var b1=new B()
var b2=new B()
b1.name='change'
b2.color.push('red')
console.log(b1.name)
console.log(b2.name)
console.log(b1.color)
console.log(b2.color)
===》
change
a
["green", "yellow", "red"]
["green", "yellow", "red"]
4.
var length=10;
    function fn(){
      console.log(this.length)
    }
    var obj={
      length:5,
      methed:function(fn){
        fn() 
        arguments[0]()
      }
    }
    obj.methed(fn,1,2)
==>
10  //this为window
3 arguments类数组长度

5.
const promise=new Promise((res,rej)=>{
    res('success')
    rej('error')
    res('success2')
  })
  promise.then((res)=>{
    console.log('then'+res)
  }).catch((err)=>{
    console.log('catch'+err)
  })
=》
  thensuccess

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值