Last active
May 1, 2024 03:49
-
-
Save Deri-Kurniawan/a8b1a41a5094dc9a8a9ee725776c2f7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hoisting is a condition where javascript seems to move a variable or function to the top of the scope before the code is executed. | |
// Any variable or function that is called before it is declared should be an error but, that is javascript hoisting, JavaScript seems to move it to the top of the scope before the code is executed. | |
// Everything is hoisted even if using var, let, const but var will not cause an error, if with let and const it will cause an error and is called a “temporal dead zone” (TDZ). meaning that the new variable can be called after the declaration | |
// Example 1 | |
console.log(abc); // variable call before it is declared | |
var abc; | |
// Example 2 | |
sayHello(); // function call before it is declared | |
function sayHello() { | |
console.log("Hello!"); | |
} | |
// Example 3 | |
increment(num = 5) // both undeclared on it but callable, given a value of 5 and having an output of 6? | |
function increment(num) { | |
console.log(num + 1) | |
} | |
var num = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment