Objects, Functions, and Classes25% of the exam
Functions: arrows, parameters, this and callbacks
How to pick the right function form for a requirement: passing references versus calling, arrow function syntax and limits, default, rest and destructured parameters, the rules that decide this (including call, apply, bind and callbacks), higher-order helpers, IIFEs and generators.
Given a business requirement, locate the best function implementation.
~8 min read · 15 practice questions ·
What the exam expects
- Given a requirement, choose between a function declaration, a function expression, an arrow function, an IIFE and a generator, and reject the forms that break.
- Pass a function as a callback by reference instead of calling it, and read what a callback-based snippet logs.
- Write parameters that meet a calling contract: defaults, rest parameters and destructured options objects.
- Predict
thisin a method call, a detached call, a callback,call/apply/bindand an arrow function, and pick the fix that restores it. - Read higher-order helpers (
once, memoize, curried factories) and predict their output. - Key terms: first-class function (a value you can pass, return and store); callback (a function passed to another function to be called later); higher-order function (takes or returns a function); lexical
this(an arrow function'sthis, taken from the scope where it was defined); bound function (a copy made bybindwhosethisand leading arguments are fixed).
Key facts
Hoisting
- Detail
- Declarations hoist with their body; function expressions and arrows do not
Concise arrow body
- Detail
- Returns its expression; a braced body without
returnreturnsundefined
Arrow returning an object
- Detail
- Wrap the literal:
() => ({ a: 1 })
Arrow and
new- Detail
- Throws TypeError; arrows have no
prototype
Default trigger
- Detail
- Missing argument or
undefinedonly;nulland0are kept
Rest parameter
- Detail
- One per function, last position, a real Array
Plain call
this- Detail
undefinedin strict mode,globalThisin non-strict code
call vs apply- Detail
- Arguments listed individually vs as an array
Re-binding
- Detail
- Binding a bound function again ignores the new
thisArg
Array method
thisArg- Detail
map(callbackFn, thisArg)setsthisfor every callback call
Object keys
- Detail
- Non-Symbol property names are coerced to strings
Generator call
- Detail
- Returns a generator;
next()returns{ value, done }
Sources for this section (10)
- Functions (JavaScript Guide)developer.mozilla.org (opens in a new tab)
- Arrow function expressionsdeveloper.mozilla.org (opens in a new tab)
- Default parametersdeveloper.mozilla.org (opens in a new tab)
- Rest parametersdeveloper.mozilla.org (opens in a new tab)
- thisdeveloper.mozilla.org (opens in a new tab)
- Function.prototype.apply()developer.mozilla.org (opens in a new tab)
- Function.prototype.bind()developer.mozilla.org (opens in a new tab)
- Array.prototype.map()developer.mozilla.org (opens in a new tab)
- Property accessorsdeveloper.mozilla.org (opens in a new tab)
- function*developer.mozilla.org (opens in a new tab)
- Why does `orders.forEach(logOrder())` fail when `logOrder` returns nothing?
- When is a default parameter value used?
- Why does a regular `function` callback passed to `setTimeout` inside a method log `NaN` for `this.count++`?
- How do you make an arrow function return an object literal?
- What does calling a generator function return?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the JavaScript Developer pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 24 lessons of the JavaScript Developer guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Inline practice questions and one-click topic practice (15 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams