Posts

Showing posts from December, 2019

JS Tip - Use variable parameters for setTimeout()

Image
setTimeout function allows us to sets a timer which executes a function or specified piece of code once the timer expires. Generally to call a function with parameter inside setTimeout we wrap the function inside anonymous function. But we can pass the function parameters directly !! const logger = message => { console.log(message); }; // Using anonymous function setTimeout(() => { logger("Hello!!"); }, 1000); // Pass parameter to callback function directly // setTimout(function, delay, ..args) setTimeout(logger, 1000, 'How are you?')