Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created August 4, 2023 15:18
Show Gist options
  • Save suhailgupta03/880ed699fb7618532774c4d94bfa49ab to your computer and use it in GitHub Desktop.
Save suhailgupta03/880ed699fb7618532774c4d94bfa49ab to your computer and use it in GitHub Desktop.
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