Saved Bookmarks
| 1. |
JavaScript Hoisting |
|
Answer» Prior to executing the code, the interpreter appears to relocate the declarations of functions, variables, and classes to the top of their scope using a process known as Hoisting in JavaScript. Functions can be securely utilised in code before they have been declared thanks to hoisting. Variable and class declarations are likewise hoisted, allowing them to be referenced prior to declaration. It should be noted that doing so can result in unforeseen mistakes and is not recommended. There are usually two types of Hoisting:
function display(inputString) { console.log(inputString); // 'Lion' gets logged }
var x // Declaration of variable x x = 7; // Initialization of variable x to a value 7 console.log(x); // 7 is logged post the line with initialization's execution. |
|