4

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Drahcir
  • 11,772
  • 24
  • 86
  • 128
  • Possible duplicate: *[Why does this JavaScript code print "undefined" on the console?](https://stackoverflow.com/questions/10263190/why-does-this-javascript-code-print-undefined-on-the-console)* – Peter Mortensen Oct 20 '20 at 17:18

2 Answers2

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"
Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
2

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Renato Zannon
  • 28,805
  • 6
  • 38
  • 42