CodePeekPlay free puzzles
45 more aha moments · upcoming

Your 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 topics

Browse 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.

  1. A moving targetCaptured bindings
  2. A saved snapshotBinding versus value
  3. One counter, two callsPrivate state
  4. Separate little worldsFactory invocations
  5. Sibling closuresShared environment
  6. A binding per laplet loop capture
  7. One binding for every lapvar loop capture
  8. The parameter pocketParameter capture
  9. The object in the pocketCaptured references
  10. Default at call timeDefault parameters
  11. Which name did it keep?Lexical scope
  12. 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.

  1. Just one level deepObject spread
  2. Independent outer arrayArray spread
  3. Copied array, shared itemShallow array copy
  4. Sort stays putIn-place sort
  5. Turn it aroundIn-place reverse
  6. The removed piecessplice return value
  7. The target changesObject.assign
  8. Take a number outPrimitive destructuring
  9. A missing slotdelete versus length
  10. Fill with one objectShared fill value
  11. New array, changed objectsMutating map callback
  12. 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.

  1. Add before you joinLeft-associative addition
  2. One plus convertsUnary numeric conversion
  3. Arrays meet plusArray primitive conversion
  4. The nullish pairLoose equality rules
  5. Not equal to itselfNaN comparisons
  6. Return the operandLogical operand results
  7. Empty turns numericNumber conversions
  8. Letters or numbers?Relational conversion
  9. Inside the interpolationTemplate expressions
  10. An object becomes a numberCustom primitive conversion
  11. 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.

  1. The executor is immediatePromise construction
  2. Return down the chainChained values
  3. A value that never leftMissing handler return
  4. Catch and continueRejection recovery
  5. Finally keeps the valuefinally passthrough
  6. Await a plain valueAsync continuation
  7. The next link waitsReaction queue order
  8. Results keep their seatsPromise.all result order
  9. A throw changes the pathThrown handler errors
  10. 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.