AI Workshop: learn to build apps with AI →
Functions: Nesting functions

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


Functions can be defined inside other functions:

const test = function() {
  const dosomething = function() {
    /* do something */
  }
  dosomething()

  return "test"
}

Arrow functions can contain other arrow functions, or regular functions too. You can mix them:

const test = () => {
  const dosomething = () => {}
  dosomething()
  return "test"
}

The nested function cannot be called from outside the enclosing function, only from inside it.

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