??? | Sololearn: Learn to code for FREE!



Why is it just written as i = 4 without writing var

5/16/2018 2:16:19 PM

Varshini Perumbala

4 Answers

New Answer


Javascript is permissive by default, you can assign values without declaring it with var/let/const. The engine creates a global variable for you if there does not exist one. Note: In strict mode you can't assign values without declaring them 1st; it will be a reference error: variable not defined.


Because Javascript is really accommodating. It automatically determines the type based upon its data.


please note that: for(var i=0;i<4;i++){} is better than: for( i=0;i<4;i++){}. Never ever use the second one since your iterator now has no usefulness outside of the loop.You do not junk variables all over your code


Oh!!! Thanks!!