bhylu.com

Advertisements

Function Definitions

A declaration names a function in its scope. A function expression creates a value at the point the expression runs.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

function add(a, b) { return a + b; }
const subtract = (a, b) => a - b;
console.log(add(5, 2), subtract(5, 2));

What happens

The outputs are 7 and 3.