1

In the JavaScript console in Chrome, if I don't use var, then the value assigned is displayed.

a = 2
// <- 2

If I do use var, then the value is not displayed.

var b = 3
// <- undefined

Why the difference?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
  • 2
    Because the console executes the code and then displays its result. The result of a `var` statement (with or without assignment) is `undefined`. The result of `a=2` is 2, which is why you can say `c=b=a=2` to assign the same value to several variables at once. – nnnnnn Feb 22 '16 at 05:06

0 Answers0