MDN self-hosted library · e01.org

Callback function

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
let value = 1;

doSomething(() => {
  value = 2;
});

console.log(value); // 1 or 2?
js
// Synchronous
function doSomething(callback) {
  callback();
}

// Asynchronous
function doSomething(callback) {
  setTimeout(callback, 0);
}