Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 651
Drahcir Avatar asked Sep 01 '25 16:09

Drahcir


1 Answers

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"
like image 190
Has QUIT--Anony-Mousse Avatar answered Sep 04 '25 07:09

Has QUIT--Anony-Mousse