CCA Prep

Lesson 2.1Lesson 7 of 24

Choosing a function implementation

Given a business requirement, locate the best function implementation.

Choosing a function implementationWhat does the function need?Callable before itslineFunctiondeclarationhoisted with itsbodyThe this of thesurrounding codeArrow functionno own this orargumentsAny number ofargumentsRest parameterfunction f(...args)Private statebetween callsClosurea variable in theouter function

Key points

  1. 1Function declarations are hoisted with their body. A function expression in var is undefined before its line; in let or const it throws.
  2. 2Arrow functions have no own this or arguments: they use those of the surrounding code. They are not constructors, so new throws.
  3. 3A default parameter is used only when the argument is undefined, and it is evaluated again on every call.
  4. 4Rest parameters collect arguments into a real array; spread passes an array as separate arguments.
  5. 5A closure keeps access to the variables of the scope where the function was created, even after the outer function has returned.
What the exam guide checks here

Objective wording from the exam guide (English).

  • 2.1.K1Function declarations, expressions and arrow functions: hoisting, this, arguments
  • 2.1.K2Default, rest and spread parameters; higher-order functions and callbacks
  • 2.1.K3Closures
  • 2.1.S1Pick the function implementation that meets a requirement

Lock it in

Answer scenario questions on this topic. Every option comes with an explanation.

Practise 2.1 · 12 questions