Skip to content

Commit 8376a00

Browse files
committed
Section 9: Callbacks
1 parent 26b0f56 commit 8376a00

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

09-An-Advanced-Look-at-Functions/01/01.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ pickOne(cry, rage)
322322

323323
// Functions as Arguments ******************************
324324
// Example 21
325+
/*
325326
console.log('\n')
326327
function multiplyByNo1(num) {
327328
// Function expression, anonymous functiion
@@ -383,4 +384,16 @@ console.log(isInNineties(1992)) // true
383384
console.log('\n')
384385
const isNiceWeather = makeBetweenFunc(60, 79)
385386
console.log(isNiceWeather(45)) // false
386-
console.log(isNiceWeather(76)) // true
387+
console.log(isNiceWeather(76)) // true
388+
*/
389+
390+
// Callbacks ******************************
391+
// Example 24
392+
/*
393+
console.log('\n')
394+
// after 5 seconds run the func
395+
// setTimeout(func, 5000);
396+
setTimeout(function () {
397+
console.log('setTimeout, 2000');
398+
}, 2000);
399+
*/

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,11 @@ const inAgeRange = makeBetweenFunc(18, 100);
190190
191191
inAgeRange(17); // false
192192
inAgeRange(68); // true
193-
```
193+
```
194+
195+
## 8. Callbacks
196+
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function. So any time we pass a function to another function and it's executed in that function, we would call it a callback function
197+
198+
**tons of the really useful built-in methods in JavaScript expect you to pass in a callback**
199+
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

0 commit comments

Comments
 (0)