PNL Learn

JavaScript Functions in Depth

Scope, closures, arrows, this and higher-order functions.

Functions are where JavaScript stops being a list of statements and becomes a language you can build with. You will declare, call and return, see why a missing argument is undefined instead of an error, and learn how scope, hoisting and the temporal dead zone decide which variable a name means. Then closures and private state, functions as values, arrow functions and callbacks with map, filter and sort, default, rest and spread parameters and options objects, the rules for this with call, apply and bind, and finally recursion and higher-order wrappers such as once, memoize and compose. Every idea is practiced in small programs checked by tests, and the course calls out each place JavaScript differs from Python's functions.

IntermediateJavaScript6 lessons64 exercisesAbout 4 h
Create a free account

What you will learn

  • Declaring and calling functions
  • Scope and hoisting
  • Closures
  • Arrow functions and callbacks
  • Default, rest and spread parameters
  • this, call, apply and bind
  • Recursion and higher-order functions

Lessons

  1. 1

    Declaring and Calling Functions

    Declare, call and return; parameters versus arguments; missing arguments; locals, shadowing and methods.

    11 exercises

  2. 2

    Scope, Hoisting and Closures

    Global, function and block scope, var and hoisting, the temporal dead zone, closures with private state, and IIFEs.

    10 exercises

  3. 3

    Functions as Values

    Store and pass functions, named and anonymous expressions, arrow functions, callbacks with forEach, map, filter and sort, and functions that return functions.

    11 exercises

  4. 4

    Flexible Parameters

    Default values and when they apply, rest parameters, spread at the call site, and destructured options objects as named parameters.

    10 exercises

  5. 5

    this, call, apply and bind

    Predict this in a method call, a plain call, an arrow function and a method passed as a callback, and fix it with bind, call or apply.

    10 exercises

  6. 6

    Recursion, Decorators and Putting It Together

    Recursive functions with base cases, the call stack RangeError, and higher-order wrappers: once, a logger, memoize and compose, used to build real tools.

    12 exercises

How you practice

You practice in the browser and every exercise gives you feedback right away. This course uses these formats:

  • Code exercise: 23
  • Fix the bug: 14
  • Predict the output: 9
  • Type the answer: 6
  • Fill in the blank: 5
  • Multiple choice: 4
  • Match the pairs: 2
  • Spot the bug: 1

Aligned to

CS2023ACM / IEEE-CS / AAAISource
  • Software Development Fundamentals
    • SDF-FundamentalsFundamental Programming Concepts and Practices
JSE-40-01: Certified Entry-Level JavaScript ProgrammerJS InstituteSource
  • Variables, Data Types, and Type Casting
    • 2.1.1Use variables effectively
  • Functions
    • 5.1.1Declare and call functions
    • 5.2.1Use parameters, local variables and shadowing
    • 5.3.1Use function expressions and first-class functions
    • 5.4.1Use recursion
    • 5.5.1Use synchronous and asynchronous callbacks
    • 5.6.1Use arrow functions
JSA-41-01: Certified Associate JavaScript ProgrammerJS InstituteSource
  • Classless Objects
    • 1.7Use methods and this
  • Advanced Functions
    • 4.1Default values, rest parameters and spread
    • 4.2Closures and IIFEs
    • 4.3this with call, apply and bind
    • 4.4Function decorators
MDN Curriculum (core)MozillaSource
  • JavaScript fundamentals
    • 6.4Arrays
    • 6.7Functions
    • 6.8Object basics

Proto Node Labs is not affiliated with or endorsed by ACM / IEEE-CS / AAAI, JS Institute and Mozilla. Exam names are trademarks of their owners.