Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

settimeout in a for loop javascript

// make sure to use "let" and not "var" if you want to capture
// the value of the external variable in a closure

  for (let i = 0; i < 5; i++) {
    setTimeout(() => console.log(i), 0);
  }
Source by learn.coderslang.com #
 
PREVIOUS NEXT
Tagged: #settimeout #loop #javascript
ADD COMMENT
Topic
Name
3+4 =