Overriding a local variable with var in JavaScript

I have a pretty general question regarding JavaScript and local variables. My question is what is the difference between the following and if there is:

function bla { var a = 2; // local variable a = 3; // the local variable a gets a new value // Would do the following line anything different // (than simply asigning this value?) var a = 4; } 

I suppose I will not get two local variables named a. In other languages, this is even a mistake. So what do you need to use for this?

+8
javascript var
source share
1 answer

Any use of var inside a function will be raised. Subsequent applications of the same variable in the same area do not affect.

It has the same meaning as a = 4; .

+13
source share

All Articles