From cc62f70f2fefa64b8d6458aa020dc73299b683e9 Mon Sep 17 00:00:00 2001 From: Rahul RK <47377566+DevTMK@users.noreply.github.com> Date: Wed, 18 Nov 2020 20:36:26 +0530 Subject: [PATCH] js-basics: Fix setTimeout syntax --- 2-js-basics/2-functions-methods/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/2-js-basics/2-functions-methods/README.md b/2-js-basics/2-functions-methods/README.md index ac498ddc..4c75ca35 100644 --- a/2-js-basics/2-functions-methods/README.md +++ b/2-js-basics/2-functions-methods/README.md @@ -139,7 +139,7 @@ function displayDone() { console.log('3 seconds has elapsed'); } // timer value is in milliseconds -setTimeout(3000, displayDone); +setTimeout(displayDone, 3000); ``` ### 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: ```javascript -setTimeout(3000, function() { +setTimeout(function() { 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! @@ -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: ```javascript -setTimeout(3000, () => { +setTimeout(() => { console.log('3 seconds has elapsed'); -}); +}, 3000); ``` ### When to use each strategy