CodingNic

Functions

Module Overview

Functions 5 min read

Module Overview

Functions

Functions let you package up a block of code and reuse it wherever you need it, instead of copying and pasting the same logic over and over. This module covers how to write, call, and organize functions, including two ideas that trip up a lot of beginners: closures and recursion.

Why This Matters

Every JavaScript program you’ll ever write is built out of functions calling other functions. Array methods take functions as arguments, event handlers are functions, and organizing a program well mostly comes down to organizing it into well-named functions that each do one thing.

What You’ll Learn

  • The different ways to write a function: declarations, expressions, and arrow functions
  • Parameters, default parameters, and rest parameters for handling any number of arguments
  • Return values, and what a function returns when you don’t write return at all
  • Closures: how a function can remember variables from where it was created
  • Recursion: a function that calls itself to solve a smaller version of the same problem
  • Higher-order functions: functions that take other functions as arguments or return them

Outcome

By the end of this module, you’ll be able to write your own functions confidently, understand how closures work under the hood, and recognize when a problem calls for recursion.

Let’s get started.