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)

11th Jun 2020, 7:06 PM
vardhan js
vardhan js - avatar
3 Respuestas
+ 1
var bb declares the variable within function war() but not globally so cannot reference it outside of the function
11th Jun 2020, 7:17 PM
JME
+ 1
Yes we cannot access variable defined in function scope. It will call as local variable. To access you need to make global variable.
11th Jun 2020, 7:18 PM
A͢J
A͢J - avatar
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)
12th Jun 2020, 10:00 AM
Ore
Ore - avatar