Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Advanced JavaScript

You're reading from   Advanced JavaScript Speed up web development with the powerful features and benefits of JavaScript

Arrow left icon
Product type Paperback
Published in Jan 2019
Publisher
ISBN-13 9781789800104
Length 330 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Zachary Shute Zachary Shute
Author Profile Icon Zachary Shute
Zachary Shute
Arrow right icon
View More author details
Toc

Callbacks


Callbacks are the most basic form of JavaScript asynchronous programming. In the simplest terms, a callback is a function that gets called after another function completes. Callbacks are used to handle the response of an asynchronous function call.

In JavaScript, functions are treated like objects. They can be passed around as arguments, returned by functions, and saved into variables. A callback is a function object that is passed as an argument into a higher order function. A higher order function is simply a mathematics and computer science term for a function that takes one or more functions as arguments (callbacks) or returns a function. In JavaScript, a higher order function will take a callback as a parameter. Once the higher order finishes doing some form of work, such as an HTTP request or database call, it calls the callback function with the error or return values.

As mentioned in the Event Loop section in Asynchronous Programming, JavaScript is an event driven language...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image