Functions

A function is a reusable block of code you can run whenever you need it, optionally passing in values and getting a value back.

Declaring and calling a function

Try it yourself
Console output

name is a parameter — a placeholder for whatever value gets passed in when the function is called. return sends a value back out.

Arrow functions

Arrow functions are a shorter way to write a function, especially for simple ones:

Try it yourself
Console output
Note: when an arrow function's body is a single expression, the result is returned automatically — no return keyword needed.