Skip to content

Commit 57aa020

Browse files
committed
Section 9: Hoisting
1 parent 8376a00 commit 57aa020

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

09-An-Advanced-Look-at-Functions/README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,40 @@ A callback function is a function passed into another function as an argument, w
197197

198198
**tons of the really useful built-in methods in JavaScript expect you to pass in a callback**
199199

200-
Anonymous function: Sometimes we just need a one time use function, We don't need it to be a standalone function, in which case we use anonymous func
200+
Anonymous function: Sometimes we just need a one time use function, We don't need it to be a standalone function, in which case we use anonymous func
201+
202+
## 9. Hoisting
203+
Variables order declaration, variables declarations made with LET and CONS are not hoisted
204+
205+
Order of hoisting
206+
1. var animal // animal = undefined
207+
2. console.log(animal); // undefined
208+
3. animal = 'tiger';
209+
210+
```
211+
console.log(animal); // Error: Cannot access 'animal' before initialization
212+
let animal = 'tiger';
213+
```
214+
**Functions are hoisted at the top of the file**
215+
216+
```
217+
function howl() {
218+
console.log('AWOOOOO');
219+
}
220+
howl(); // 'AWOOOOO'
221+
```
222+
223+
```
224+
howl(); // 'AWOOOOO'
225+
function howl() {
226+
console.log('AWOOOOO');
227+
}
228+
```
229+
230+
**Functions expressions are not hoisted**
231+
```
232+
hoot(); // Error
233+
let hoot = function() {
234+
console.log('HOOOO HOOOOO');
235+
}
236+
```

0 commit comments

Comments
 (0)