🆖 Karan Oza Profile picture
👋Hello, How can I Help You as a Developer, Freelancer or as a HUMAN BEING 🙋 Co-founder & CTO @industriestadka | Youtube channel👇

Sep 24, 2020, 9 tweets

🧵Asynchronous JavaScript & Callback🧵

⚡️Informative thread with examples

#100DaysOfCode #CodeNewbie #javascript

Synchronous :

- Synchronous operations in JavaScript entails having each step of an operation waits for the previous step to execute completely.

- This means no matter how long a previous process takes, subsequent process won't kick off until the former is completed.

Asynchronous :

- Asynchronous operations, on the other hand, defers operations.

- Any process that takes a lot of time to process is usually run alongside other synchronous operation and completes in the future.

✨ Callback Function :

- When function simply accepts another function as an argument, this contained function is known as callback function.

- Using callback functions is a core functional programming concept, and you can find them in most JavaScript code; like setInterval

✅ Example - setInterval accepts a callback function as its first parameter and also a time interval. Another example using .map();

✅ In the example above, we used the .map() method to iterate through the array list, the method accepts a callback function which states how each element of the array will be manipulated.

✅Callback functions can also accept arguments as well.

- Callback functions can be named or anonymous functions.

✨ The Given function is assigned a name greeting and has an argument of name. We're also using an ES6 template string. Let’s use this function as a callback function.

- Notice the usage of the callback? The succeeding brackets, () after the function are not used when passing the function as a parameter.

✨Note: The callback function is not run unless called by its containing function, it is called back. Hence, the term call back function

✨Multiple functions can be created independently and used as callback functions.

⚡️These create multi-level functions. When this function tree created becomes too large, the code becomes incomprehensible sometimes and is not easily refactored. This is known as CALLBACK HELL.

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling