0
in this case var keyword is not working in function block.why??
if(true){ var aa="vardhan123"; } console.log(aa) function war(){ var bb="hello world"; } war() console.log(bb)
3 Respuestas
+ 1
var bb declares the variable within function war() but not globally so cannot reference it outside of the function
+ 1
Yes we cannot access variable defined in function scope. It will call as local variable. To access you need to make global variable.
0
Variables declared by var are function-scoped. To declare a global variable use window object. Like this
function war(){
window.bb="hello world";
//Or just
bb="hello world";
}
war()
console.log(bb)