What is JavaScript hoisting

JavaScript hoisting is a behavior in JavaScript where variable and function declarations are moved to the top of their containing scope during the compile phase. This means that you can use functions and variables even before you declare them in your code.

Keywords: JavaScript, hoisting, variable declaration, function declaration, compile phase
Description: Understanding JavaScript hoisting is crucial for debugging and writing effective JavaScript code, as it helps developers grasp how the execution context works.
// Example of hoisting with variables and functions console.log(myVar); // undefined due to hoisting var myVar = 5; myFunction(); // "Hello, World!" due to function hoisting function myFunction() { console.log("Hello, World!"); }

Keywords: JavaScript hoisting variable declaration function declaration compile phase