Drahcir
Drahcir

Reputation: 11972

Why does Chrome & FireFox console print '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

Upvotes: 4

Views: 4496

Answers (2)

Renato Zannon
Renato Zannon

Reputation: 29981

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

Upvotes: 2

Has QUIT--Anony-Mousse
Has QUIT--Anony-Mousse

Reputation: 77485

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"

Upvotes: 5

Related Questions