最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does Chrome & FireFox console print 'undefined'? - Stack Overflow

programmeradmin0浏览0评论

Take this simple Test object and paste it into the console. You'll see that it says undefined. The object is working because it also prints 123, but what is the undefined about?

Test:

var Test = new (function(){
    return {
        get testing(){
            return "123";
        }
    }
});

console.log(Test.testing);

Console Output:

123
undefined

Take this simple Test object and paste it into the console. You'll see that it says undefined. The object is working because it also prints 123, but what is the undefined about?

Test:

var Test = new (function(){
    return {
        get testing(){
            return "123";
        }
    }
});

console.log(Test.testing);

Console Output:

123
undefined
Share Improve this question edited Oct 20, 2020 at 17:16 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Nov 10, 2012 at 13:25 DrahcirDrahcir 12k25 gold badges88 silver badges128 bronze badges 1
  • Possible duplicate: Why does this JavaScript code print "undefined" on the console? – Peter Mortensen Commented Oct 20, 2020 at 17:18
Add a ment  | 

2 Answers 2

Reset to default 5

That is the return value of console.log.

Try

console.log(1);

which gives

1
undefined

However, if you type just

Test.testing

that gives only

"123"

undefined is the return value from the console.log call.

发布评论

评论列表(0)

  1. 暂无评论