0

Using keyword var in js

I want to ask, what is purpose of using keyword var before variable name, when it works same way without the keyword. I use var always when I declare a variable. But I had found a code, where inside for statement had been iteration variable used without the var keyword and it confused me. Thanks for answers! (pardon my english, I’m not native speaker)

28th Jan 2019, 10:27 PM
Igor Novak
Igor Novak - avatar
1 Respuesta
+ 3
Many new browsers are smart and can read code with a few things missing. However, officially you must use var, otherwise the code won't run in old browsers and may cause subtle errors even in new browsers.
28th Jan 2019, 10:31 PM
James
James - avatar