Functions: Nesting functions

Functions can be defined inside other functions:

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

  return "test"
}

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

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

The nested function cannot be called from the outside of the enclosing function. Just 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
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. Launching May 21, 2024. Join the waiting list!