Created
August 4, 2023 15:18
-
-
Save suhailgupta03/880ed699fb7618532774c4d94bfa49ab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
console.log(x); | |
var x = 1; | |
// Here x is undefined | |
// because JavaScript hoists declarations | |
// which means that the declaration is | |
// automatically moved to the top of | |
// the current scope | |
greet(); | |
// greet function is hoisted | |
// only because of hoisting we can call | |
// the function before declaring it | |
function greet() { | |
console.log("Hello..!"); | |
} | |
console.log(y); | |
let y = 1; | |
// x is not hoisted | |
// because it is declared using let | |
// let and const are not hoisted | |
// only var is hoisted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment