0

What happen when we don't add the var (variable)or a simpler question whats the purpose of var

6th Mar 2021, 4:02 AM
Duy Gia
Duy Gia - avatar
3 ответов
+ 1
before ES6(ES2015) the only way of declaring a variable was using var keyword. now that we have let and const there is no need for using var keyword we use let for a variable that does'nt have a constant value & we use usually const for a variable that has a constant value
6th Mar 2021, 6:37 AM
Nima
0
var is used for declaring variable. Without var keyword if you declare a variable that becomes global variable.
6th Mar 2021, 4:05 AM
TOLUENE
TOLUENE - avatar
0
function test(){ var a=true;//here it is local variable you can not access it outside the function. b=4; // as this is not declared with the keyword var let const so it becomes a global variable you can access it outside function } test() alert(b)//output 4 alert(a)// a is not defined
6th Mar 2021, 4:09 AM
TOLUENE
TOLUENE - avatar