Functions for Reusability

Instead of giving those instructions for every hamburger, we can group and name them as a single function:

function makeHamburger() {
  Add bread
  Add burger patty
  Add pickles

A function is a named sequence of instructions, packaged as a unit, that performs a specific task.

We’ve defined the function by giving it instructions and a name, but how do we use it? We use a function by calling it. When we call makeHamburger() we expect all of its steps to be executed.


Build hamburgers with a function: In this example you can call the function by clicking the makeHamburger() button. Make three hamburgers by calling the function three times.

Folder Icon

Sign up to start coding

Already have an account?