Curriculum Series

Can callbacks be synchronous?

Can callbacks be synchronous?

Can callbacks be synchronous?

JavaScript

Synchronous callback

Yes, callbacks can be synchronous

JAVASCRIPT
1const gods = ['Apollo', 'Artemis', 'Ares', 'Zeus'];
2
3gods.forEach(function (eachName, index) {
4 console.log(index + '. ' + eachName);
5});

In this example given above we loop through an array of Greek gods and print the index numbers and values to the console. The expected parameter of forEach() is a callback function, which itself takes two parameters, a reference to the array name and index values. However, it doesn't wait for anything it runs immediately.

Finished reading?

Mark this topic as solved to track your progress.