const d = 4 let a = 1 if (true) { let a = 4 var b = 2 if (a < 5) { var c = 1 b = 5 } } console.log(a + b + c);
What is is the output and why?
a) The output is 7 because a, b and d are globally scoped variables
b) The output is 7 because b and c are globally scoped variables
The variable declared outside
of a function becomes GLOBAL.
The global variable has global scope: all scripts
and functions on the web page can be accessed.
for example, in the given code
const d = 4 let a = 1 if (true) { let a = 4 var b = 2 if (a < 5) { var c = 1 b = 5 } } console.log(a + b + c);
The output is 7 because b and c are globally scoped variables.
Get Answers For Free
Most questions answered within 1 hours.