Home › JavaScript Tutorial › Functions
Functions
Name a block of code so you can reuse it.
A function takes inputs (parameters) and can return an output. Arrow functions are a short form.
Example code
<p id="o"></p>
<script>
function add(a, b) { return a + b; }
const square = n => n * n;
o.textContent = "2 + 3 = " + add(2, 3) + ", 4 squared = " + square(4);
</script>