r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

Show parent comments

12

u/ThatBriandude May 28 '19 edited May 28 '19

and you just need to execute it in the next tick (iteration of the event loop) instead.

I consider myself pretty well versed in javascript however I can not imagine what you mean with this. How would "execute it in the next tick" look in code?

10

u/envis10n May 28 '19

setImmediate sometimes, you run into a max callstack issue for function calls if you don't ensure that the next call comes on the next tick. This is especially important for recursive functions or looping functions that might call itself again.

6

u/ShellbertShellbach May 28 '19

Note: setImmediate is not a standardized feature of JS and only exists in Node.js, IE10, IE11, and pre-Chromium Edge.

1

u/envis10n May 28 '19

Yes, I was just providing a method for doing so. However, you could also accomplish it through other means. Hopefully that doesn't confuse anyone that read it.