Reword some articles

This commit is contained in:
Chalarangelo
2021-11-06 21:00:44 +02:00
parent 04ee60671b
commit 4670439e56
3 changed files with 12 additions and 12 deletions

View File

@ -6,14 +6,14 @@ authors: chalarangelo
cover: blog_images/sleepy-cat.jpg
excerpt: Learn all the different ways you can implement a `sleep()` function in JavaScript.
firstSeen: 2020-08-04T20:08:54+03:00
lastUpdated: 2021-06-12T19:30:41+03:00
lastUpdated: 2021-11-06T20:51:47+03:00
---
JavaScript does not come with a `sleep()` function out of the box and that is probably a good idea considering the environments where it runs and the trouble such a function could cause if used incorrectly. The closest equivalent of such a function is `setTimeout`, however there are other, less common ways to implement a function that will freeze the current thread for a specified amount of time.
JavaScript does not come with a `sleep()` function out of the box. That's probably a good idea considering the environments where it runs and the trouble it could cause if used incorrectly. The closest equivalent is the `setTimeout` function, but there are other, less common ways to implement a function that will pause execution for a specified amount of time.
### setTimeout
JavaScript's `setTimeout` sets a timer which executes a function or specified piece of code once the timer expires. Only the code inside the `setTimeout` callback will execute after the timer expires, which can lead to nesting issues, as well as code executing out of order if you are not careful.
JavaScript's `setTimeout` sets a timer which executes some code once the timer expires. Only the code inside the `setTimeout` callback will execute after the timer expires. This can lead to nesting issues, as well as code executing out of order if you are not careful.
```js
const printNums = () => {