Why does Chrome & FireFox console print undefined?

泄露秘密 提交于 2020-01-14 14:39:13

问题


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

回答1:


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"



回答2:


undefined is the return value from the console.log call



来源:https://stackoverflow.com/questions/13322435/why-does-chrome-firefox-console-print-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!