DEV Community

Discussion on: 24 modern ES6 code snippets to solve practical JS problems

 
madza profile image
Madza

That's the point - they behave the same, but you don't have to create new variables for the same functionality throughout your app. Instead you just use the same function once you need timer functionality for something.

Furthermore, if you need different function signature, you can use the latter assigning it to different var.

Thread Thread
 
vonheikemen profile image
Heiker

they behave the same, but you don't have to create new variables for the same functionality throughout your app.

if I assign setTimeout that will force me to create new unnecesary variables in the entire app? And that doesn't happen if I wrap it in a function?

Thread Thread
 
piterden profile image
Denis Efremov
/**
 * Sleep pause.
 *
 * @param {Number} time The time in milliseconds.
 * @return {Promise<void>}
 */
const sleep = (time) => new Promise((resolve) => {
  setTimeout(resolve, time)
})