Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JS Callbacks

“I’ll call back later!”

A callback is a function provided as an argument to another function. This approach enables one function to invoke another, with the callback running after the first function has completed.

Function Sequence

JavaScript functions are executed in the order they are called, not the order in which they are defined.

In this example, “Goodbye” will be displayed.

Example

function myFirst() {
  myDisplayer(“Hello”);
}

function mySecond() {
  myDisplayer(“Goodbye”);
}

myFirst();
mySecond();

In this example, “Hello” will be displayed.

Example

function myFirst() {
  myDisplayer(“Hello”);
}

function mySecond() {
  myDisplayer(“Goodbye”);
}

mySecond();
myFirst();