0
What happen when we don't add the var (variable)or a simpler question whats the purpose of var
3 Antworten
+ 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
0
var is used for declaring variable. Without var keyword if you declare a variable that becomes global variable.
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