Functions
We separate tiny portions of our code into a function so we can call this function multiple times, move it to a separate file, and much more.

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


In any moderately complex JavaScript program, everything happens inside functions.

Functions are a core, essential part of JavaScript.

What is a function? A function is a block of code, self contained, and we can tell our program to run that code when we need it.

Here’s a function declaration:

function test() {
  // do something
}

The // do something comment is a placeholder for a set of instructions that can be long as much as you want.

When you want to run this function, you “call it” or “invoke it”, like this:

test()

Lessons in this unit:

0: ▶︎ Introduction
1: Function parameters
2: Returning values from a function
3: Arrow functions
4: Nesting functions
5: Immediately-invoked functions
6: Recursive functions