Skip to content

Instantly share code, notes, and snippets.

@KSXGitHub
Last active December 1, 2017 15:00
Show Gist options
  • Select an option

  • Save KSXGitHub/bd4399f27744eeb513f5a1d67d647509 to your computer and use it in GitHub Desktop.

Select an option

Save KSXGitHub/bd4399f27744eeb513f5a1d67d647509 to your computer and use it in GitHub Desktop.

Alternate Solutions

Use let

for (let i = 0; i <= 4; i++) {
  setTimeout(() => console.log(i), 0)
}

Use forEach

Better than Use let IMO.

Array(5).forEach((_, i) => {
  setTimeout(() => console.log(i), 0)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment