MDN self-hosted library · e01.org

First-class function

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

js
const foo = () => {
  console.log("foobar");
};
foo(); // Invoke it using the variable
// foobar
js
function sayHello() {
  return "Hello, ";
}
function greeting(helloMessage, name) {
  console.log(helloMessage() + name);
}
// Pass `sayHello` as an argument to `greeting` function
greeting(sayHello, "JavaScript!");
// Hello, JavaScript!
js
function sayHello() {
  return () => {
    console.log("Hello!");
  };
}