You're reviewing a pull request, and you see that a developer used var to declare a variable inside a for loop. You notice that the variable is being accessed outside the loop without any issues. Why is this possible?
- Variable Hoisting
- Block Scoping (let/const)
- Function Scoping
- Global Scope
This is possible due to "Variable Hoisting" in JavaScript. Variables declared with var are hoisted to the top of their containing function or global scope. This means that the variable is accessible anywhere within that scope, even before its actual declaration in the code.
Loading...
Related Quiz
- The HTTP status code ________ indicates that the request has succeeded.
- The mechanism that allows you to use the structure of a class and alter it for use in another class is known as _________.
- Which of the following best describes a JavaScript callback function?
- In a code review, you spot the line const arr = [10, 20, 30]; followed by arr = [40, 50, 60];. What will be the outcome when this code is executed?
- What is a closure in JavaScript?