丧尸会跳小芭蕾 2017-10-05 14:58 采纳率: 0%
浏览 1192

一个ES6的笔试题目,求大神们帮忙看看~

 function Example(name){
            return this.name = name;
        }

        console.log([0,"0",[],{},null].map(i => typeof new Example(i).name));

我运行结果为:["number", "string", "undefined", "undefined", "object"]
为什么会有undefined的呐?

  • 写回答

4条回答 默认 最新

  • scottdao 2017-10-06 02:59
    关注

    因为空数组中没有值,对象中没有属性和值,故读取数组中或对象中没有的属性值,会返回一个undefined

    评论

报告相同问题?