// Anonymous function created as a function expression
(function () {});
// Anonymous function created as an arrow function
() => {};Function / notebook
Function
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
// Function declaration
function foo() {}
// Named function expression
(function bar() {});
// Arrow function
const baz = () => {};function addSquares(a, b) {
function square(x) {
return x * x;
}
return square(a) + square(b);
}
// Arrow function
const addSquares2 = (a, b) => {
const square = (x) => x * x;
return square(a) + square(b);
};function loop(x) {
if (x >= 10) return;
loop(x + 1);
}
// Arrow function
const loop2 = (x) => {
if (x >= 10) return;
loop2(x + 1);
};(function foo() {
console.log("Hello Foo");
})();
(function food() {
console.log("Hello Food");
})();
(() => console.log("hello world"))();