Play free puzzlesYour next peek at JavaScript
Closures, mutation, coercion and promise ordering. 45 additional puzzles, with four choices and clear, step-by-step explanations.
$9 USD once
Purchases are not open yet. Explore the contents below or keep playing the 15 free puzzles.
Questions about the upcoming pack or purchases? Email codepeek@brainer.one. Please don’t send payment details.
Peek inside the pack
45 puzzles · 4 topicsBrowse the full contents and four snippet previews. Answers stay under wraps here; each puzzle is prepared with four choices and a three-step explanation.
Closures12 puzzles
Captured bindings, private state, loop scope, and factory functions.
- A moving targetCaptured bindings
- A saved snapshotBinding versus value
- One counter, two callsPrivate state
- Separate little worldsFactory invocations
- Sibling closuresShared environment
- A binding per laplet loop capture
- One binding for every lapvar loop capture
- The parameter pocketParameter capture
- The object in the pocketCaptured references
- Default at call timeDefault parameters
- Which name did it keep?Lexical scope
- Return now, increment tooPostfix return
Snippet preview · Sibling closures
function box() {
let n = 2;
return { add: () => n++, read: () => n };
}
const b = box();
b.add();
console.log(b.read());What’s the output? Answer withheld in this preview.
Mutation12 puzzles
Shallow copies, shared objects, array methods, and reassignment.
- Just one level deepObject spread
- Independent outer arrayArray spread
- Copied array, shared itemShallow array copy
- Sort stays putIn-place sort
- Turn it aroundIn-place reverse
- The removed piecessplice return value
- The target changesObject.assign
- Take a number outPrimitive destructuring
- A missing slotdelete versus length
- Fill with one objectShared fill value
- New array, changed objectsMutating map callback
- Replace the local referenceReassignment versus mutation
Snippet preview · Just one level deep
const first = { inner: { n: 1 } };
const copy = { ...first };
copy.inner.n = 8;
console.log(first.inner.n);
console.log(first === copy);What’s the output? Answer withheld in this preview.
Coercion11 puzzles
Primitive conversion, equality, logical operators, and numeric surprises.
- Add before you joinLeft-associative addition
- One plus convertsUnary numeric conversion
- Arrays meet plusArray primitive conversion
- The nullish pairLoose equality rules
- Not equal to itselfNaN comparisons
- Return the operandLogical operand results
- Empty turns numericNumber conversions
- Letters or numbers?Relational conversion
- Inside the interpolationTemplate expressions
- An object becomes a numberCustom primitive conversion
- Keep the empty and falseNullish versus falsy
Snippet preview · Arrays meet plus
console.log([1, 2] + [3]);
console.log([] + 4);What’s the output? Answer withheld in this preview.
Promise ordering10 puzzles
Executors, chains, recovery, await, and microtask checkpoints.
- The executor is immediatePromise construction
- Return down the chainChained values
- A value that never leftMissing handler return
- Catch and continueRejection recovery
- Finally keeps the valuefinally passthrough
- Await a plain valueAsync continuation
- The next link waitsReaction queue order
- Results keep their seatsPromise.all result order
- A throw changes the pathThrown handler errors
- Between timer tasksMicrotask checkpoints
Snippet preview · The next link waits
const p = Promise.resolve();
p.then(() => console.log("A"))
.then(() => console.log("C"));
p.then(() => console.log("B"));
console.log("D");What’s the output? Answer withheld in this preview.