0

How var a is declared? Is it global? What scope does it have?

if ((a = 10) > 0) {
...
}

Is it like this?

var a = 10;
if (a > 0) { ... }
  • 1
    It's exactly the same as if you did `a = 10` without the if statement. – JJJ Nov 02 '16 at 10:38
  • 1
    Yes, its a global variable. You should use `use strict` to avoid such issues – Rajesh Nov 02 '16 at 10:38
  • 1
    Possible duplicate of [javascript variable scope in the IF statement](http://stackoverflow.com/questions/6964895/javascript-variable-scope-in-the-if-statement) – Rajesh Nov 02 '16 at 10:39
  • by the way, notice that (a = 10) will always be > 0. The = will set a to 10, then return that 10 to the equation. – Emmanuel Delay Nov 02 '16 at 12:47

0 Answers0