mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-25 13:06:22 +00:00
655 B
655 B
date | id | title |
---|---|---|
2020-09-11 | 6b091d50-aa10-4ba8-a652-43cd5433371e | JavaScript Callbacks |
Examples
setTimeout
setTimeout(() => { console.log("This will echo after 2 seconds!"); }, 2000);
ES6
Best practices
Prefer arrow functions as callbacks
As callbacks, arrow functions have two advantages over traditional functions:
this
is lexical and therefore safer to use.- Their syntax is more compact. That matters especially in functional programming, where there are many higher-order functions and methods (functions and methods whose parameters are functions).