Merge pull request #64 from DevTMK/update-readme

js-basics: Fix setTimeout syntax
pull/67/head
Jasmine Greenaway 4 years ago committed by GitHub
commit 89a1b452ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -139,7 +139,7 @@ function displayDone() {
console.log('3 seconds has elapsed'); console.log('3 seconds has elapsed');
} }
// timer value is in milliseconds // timer value is in milliseconds
setTimeout(3000, displayDone); setTimeout(displayDone, 3000);
``` ```
### Anonymous functions ### Anonymous functions
@ -151,9 +151,9 @@ When we are passing a function as a parameter we can bypass creating one in adva
Let's rewrite the code above to use an anonymous function: Let's rewrite the code above to use an anonymous function:
```javascript ```javascript
setTimeout(3000, function() { setTimeout(function() {
console.log('3 seconds has elapsed'); console.log('3 seconds has elapsed');
}); }, 3000);
``` ```
If you run our new code you'll notice we get the same results. We've created a function, but didn't have to give it a name! If you run our new code you'll notice we get the same results. We've created a function, but didn't have to give it a name!
@ -165,9 +165,9 @@ One shortcut common in a lot of programming languages (including JavaScript) is
Let's rewrite our code one more time to use a fat arrow function: Let's rewrite our code one more time to use a fat arrow function:
```javascript ```javascript
setTimeout(3000, () => { setTimeout(() => {
console.log('3 seconds has elapsed'); console.log('3 seconds has elapsed');
}); }, 3000);
``` ```
### When to use each strategy ### When to use each strategy

Loading…
Cancel
Save