JS and Firefox scratchpad

361 Views Asked by At

I'm using MDN guide to learn JS and I use scratchpad to try some examples.

If I write

console.log('The value of b is ' + b);
var b;

Why does console.log say "The value of b is -1" ?! It should be undefined

1

There are 1 best solutions below

6
Ricardo Rocha On

Probably you defined the var b before with the value -1.

If you try the above code, you will see that, if the variable is already instantiated and if you declare again the variable without set any value to them, the variable it will not be instantiated.

var b = -1;
console.log(b)
var b;
console.log(b)