JavaScript
Can callbacks be synchronous?
JavaScript
Synchronous callback
Yes, callbacks can be synchronous
JAVASCRIPT
1const gods = ['Apollo', 'Artemis', 'Ares', 'Zeus'];23gods.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.
Related JavaScript interview topics
Continue with nearby questions from the same topic cluster.
How do you convert a string to a number in JavaScript?How does the this keyword work in JavaScript?What are the different types of errors in JavaScript?What are the key differences between var, let, and const in JavaScript?What are the different ways to create objects in JavaScript?What is hoisting in JavaScript?