javascript - Do I need to create a variable in a for-loop? -
this question has answer here:
- when use var in javascript [duplicate] 4 answers
i'm new javascript, i'm sorry if question stupid. told when create for
-loop, should write:
for (var = 0; < 10; i++)
but forget put var
before i
:
for (i = 0; < 10; i++)
and works same. need create variable i
?
what's main difference between
var = 0
and
i = 0
in for
-loop?
when declare variable var
it's scope limited,
when don't use var
variable in global scope. means can access variable anywhere.
Comments
Post a Comment