Advanced JavaScript: classes, modules and modern syntax
The prototype and the prototype chain, class, extends and super, modules with import and export, destructuring, spread and optional chaining.
- 35 cards
- 6 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- The steps
- Scenarios
- Understand
A few cards from the deck
Prototype: what is it?
Show the answer
An object that another object delegates to: when a property is missing on the first one, the engine looks for it on that one.
A class's methods live once on its prototype; instances do not carry a copy.
What are
reste,tandvat the end?
```js
const { a, ...reste } = { a: 1, b: 2, c: 3 };
const t = [...[1, 2], 3];
let u;
const v = u?.x ?? "rien";`{ b: 2, c: 3 },[1, 2, 3],"rien"{ a: 1, b: 2, c: 3 },[[1, 2], 3],undefined{ b: 2, c: 3 },[[1, 2], 3],"rien"[2, 3],[1, 2, 3],TypeError
Show the answer
{ b: 2, c: 3 },[1, 2, 3],"rien"The rest gathers the properties not extracted (
ais excluded). The...spread lays elements out flat.u?.xstops atundefinedinstead of raising an error, and??then gives the fallback.To import a named export, write its name between …; for the default export, leave them out and pick the name.
Show the answer
To import a named export, write its name between braces; for the default export, leave them out and pick the name.
Forgetting the braces imports the default export; using them on a name that is not exported gives a
SyntaxErrorbefore anything runs.Prototype chain: what is it?
Show the answer
The sequence of objects walked from one prototype to the next, until the property is found or
nullis reached.If nothing is found at the end, the read gives
undefined; calling a missing method raisesTypeError: … is not a function.The lookup of rex.parler() along the prototype chain: which step comes after "The engine looks for parler on the rex object itself"?
- Absent too: it moves on to Animal.prototype
- It finds parler there and calls it with this equal to rex
- Absent: it moves on to rex's prototype, Chien.prototype
- With no result, it would have reached Object.prototype then null
Show the answer
Absent: it moves on to rex's prototype, Chien.prototype
The lookup goes up one link at a time and stops at the first property found; this stays the starting object,
rex, even if the method comes from a prototype.