Functions review

Functions as a black box

A function has four key characteristics

Name

Number, type, and meaning of arguments

Type and meaning of return value

Any side effects

Defining a function

const name = function

Basic structure of a function

(arguments) => { code }

Shorthand form

(arguments) => expression

Example

const double = (n) => {
  return n * 2;
};

Example of shorthand

const double = (n) => n * 2;

Writing basic functions

Standard