-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHoisting.js
More file actions
19 lines (14 loc) · 706 Bytes
/
Hoisting.js
File metadata and controls
19 lines (14 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* Hoisting : Hoisting refers to the process whereby the interpreter appears to move the declarations to the top of the code before execution:
Variables can thus be referenced before they are declared in JavaScript
Note: JavaScript only hoists declarations, not initializations, The variable will be undefined untill the line where its initialized is
reached.
Hoisting with let and var : Function expressions and class expressions are not hoisted. */
// let a;
// Following two lines will run successfully due to JavaScript hoisting
console.log(a)
greet()
var greet = function() {
console.log("Good morning")
}
var a = 9; // Declaration hoisted to the top but initialization is not
console.log(a)