0

I am new in Javascript and play around with some stuff. In Chrome console I written this code.

var a;
console.log(a)

Output:undefined undefined

Can anybody pls explane me why I am getting twice?.

enter image description here

prasanth
  • 22,145
  • 4
  • 29
  • 53
David
  • 4,266
  • 8
  • 34
  • 69

1 Answers1

0

console.log() outputs a value to the console because you called it and that is what console.log() does.

The return value of the last statement is then output to the console because you are running code on the console.

It is coincidence that those values are both undefined.

If you set var a = 1 then you would get 1 (what you logged) and then undefined (return value) instead.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • `undefined` is the return value of the `console.log` function itself. – Itay Nov 15 '16 at 07:34
  • @Quentin So you mean one undefined for `consol.log()` and other which displaying `a` value in console as laty suggesting. – David Nov 15 '16 at 07:37