Card type

parseInt()

1 card
  1. 01
    console.log(["1", "2", "3"].map(parseInt));
    

    What is printed?

    • A

      [ 1, NaN, 3 ]

    • B

      [ 1, 2, 3 ]

    • C

      [ 1, NaN, NaN ]

    • D

      [ NaN, NaN, NaN ]

typeof

1 card
  1. 02
    console.log(typeof null, typeof NaN, typeof [], typeof (() => {}));
    

    What is printed?

    • A

      object number object function

    • B

      object number object object

    • C

      null number array function

    • D

      object NaN object function

Number

1 card
  1. 03
    console.log(0.1 + 0.2, 0.1 + 0.2 === 0.3);
    

    What is printed?

    • A

      0.30000000000000004 false

    • B

      0.30000000000000004 true

    • C

      0.3 false

    • D

      0.3 true

Array.prototype.includes()

1 card
  1. 04
    const list = [NaN];
    console.log(list.indexOf(NaN), list.includes(NaN));
    

    What is printed?

    • A

      -1 true

    • B

      -1 false

    • C

      0 true

    • D

      0 false

Array.prototype.sort()

1 card
  1. 05
    console.log([10, 9, 1, 100].sort());
    

    What is printed?

    • A

      [ 100, 10, 9, 1 ]

    • B

      [ 9, 1, 10, 100 ]

    • C

      [ 1, 9, 10, 100 ]

    • D

      [ 1, 10, 100, 9 ]

var

1 card
  1. 06
    function f() {
      console.log(x);
      var x = 1;
      console.log(x);
    }
    f();
    

    What happens?

    • A

      Throws ReferenceError on the first console.log

    • B

      Prints null, then 1

    • C

      Prints 1, then 1

    • D

      Prints undefined, then 1

let

1 card
  1. 07
    function f() {
      console.log(x);
      let x = 1;
    }
    f();
    

    What happens?

    • A

      Prints undefined

    • B

      Throws ReferenceError: x is in the temporal dead zone

    • C

      Prints null

    • D

      Throws SyntaxError: x is used before it is declared

Closures

1 card
  1. 08
    for (var i = 0; i < 3; i++) {
      setTimeout(() => console.log(i));
    }
    

    What is printed?

    • A

      undefined undefined undefined

    • B

      0 0 0

    • C

      3 3 3

    • D

      0 1 2

this

1 card
  1. 09
    class Counter {
      count = 0;
      increment() {
        return ++this.count;
      }
    }
    const counter = new Counter();
    const increment = counter.increment;
    increment();
    

    What happens on the last line?

    • A

      Throws TypeError: cannot read properties of undefined

    • B

      Returns 1; counter.count is now 1

    • C

      Returns NaN

    • D

      Returns 1, but counter.count stays 0

Arrow function expressions

1 card
  1. 10
    const Point = (x, y) => ({ x, y });
    const p = new Point(1, 2);
    

    What happens on the second line?

    • A

      p is undefined

    • B

      p is { x: 1, y: 2 }

    • C

      Throws TypeError: Point is not a constructor

    • D

      p is an empty object: the return value of an arrow is ignored by new

Using microtasks in JavaScript

1 card
  1. 11
    console.log("a");
    setTimeout(() => console.log("b"), 0);
    Promise.resolve().then(() => console.log("c"));
    queueMicrotask(() => console.log("d"));
    console.log("e");
    

    In what order are the letters printed?

    • A

      a e c d b

    • B

      a b c d e

    • C

      a e d c b

    • D

      a e b c d

Promise

1 card
  1. 12
    new Promise((resolve) => {
      console.log("a");
      resolve();
    });
    console.log("b");
    

    What is printed?

    • A

      Only b: the executor runs on the next tick

    • B

      Only a: the promise is never awaited, so b is skipped

    • C

      b a

    • D

      a b

async function

1 card
  1. 13
    async function f() {
      return 1;
    }
    console.log(f());
    

    What is printed?

    • A

      Promise { 1 }

    • B

      1

    • C

      undefined

    • D

      Promise { <pending> }

await

1 card
  1. 14
    async function f() {
      console.log("a");
      await null;
      console.log("b");
    }
    f();
    console.log("c");
    

    What is printed?

    • A

      a cb is never printed because null is not a promise

    • B

      c a b

    • C

      a b c

    • D

      a c b

Promise.all()

2 cards
  1. 15
    const wait = (ms) => new Promise((r) => setTimeout(r, ms));
    
    async function run() {
      await wait(300);
      await wait(200);
      await wait(100);
    }
    

    Roughly how long does run() take to settle?

    • A

      About 0 ms: the timers start immediately and run returns before them

    • B

      About 600 ms

    • C

      About 100 ms

    • D

      About 300 ms

  2. 16
    Promise.all([
      Promise.reject(new Error("first")),
      new Promise((r) => setTimeout(() => r("second"), 10)),
    ]).then(
      (values) => console.log("ok", values),
      (err) => console.log("fail", err.message),
    );
    

    What is printed?

    • A

      fail first, after about 10 ms

    • B

      fail first, immediately (as a microtask), without waiting for the timer

    • C

      ok [ Error: first, 'second' ]

    • D

      ok [ 'second' ]

Promise.prototype.then()

1 card
  1. 17
    Promise.resolve()
      .then(() => { throw new Error("boom"); })
      .then(() => console.log("a"))
      .catch(() => console.log("b"))
      .then(() => console.log("c"));
    

    What is printed?

    • A

      a b c

    • B

      b c

    • C

      c

    • D

      b

const

1 card
  1. 18
    const list = [1];
    list.push(2);
    list = [];
    

    What happens?

    • A

      push throws TypeError: list is constant

    • B

      Both lines succeed; list ends up as []

    • C

      push succeeds; the reassignment throws TypeError

    • D

      Both lines throw

Object.freeze()

1 card
  1. 19
    const config = Object.freeze({ retries: 3, limits: { max: 10 } });
    config.limits.max = 20;
    console.log(config.limits.max);
    

    What is printed?

    • A

      10

    • B

      undefined

    • C

      20

    • D

      Nothing: the assignment throws TypeError

JSON.stringify()

1 card
  1. 20
    console.log(JSON.stringify({
      a: undefined,
      b: () => 1,
      c: NaN,
      d: [undefined],
    }));
    

    What is printed?

    • A

      {"c":null,"d":[null]}

    • B

      Nothing: it throws TypeError because a function cannot be serialised

    • C

      {"a":null,"b":null,"c":null,"d":[null]}

    • D

      {"c":"NaN","d":[]}

Symbol

1 card
  1. 21
    const id = Symbol("id");
    const user = { [id]: 42, name: "Ada" };
    console.log(Object.keys(user), JSON.stringify(user));
    

    What is printed?

    • A

      [ 'name' ] {"name":"Ada"}

    • B

      [ 'Symbol(id)', 'name' ] {"name":"Ada"}

    • C

      [ 'name' ] {"Symbol(id)":42,"name":"Ada"}

    • D

      [ 'id', 'name' ] {"id":42,"name":"Ada"}

Addition (+)

1 card
  1. 22
    console.log("5" + 2, "5" - 2, "5" * "2", null + 1, undefined + 1);
    

    What is printed?

    • A

      7 3 10 1 NaN

    • B

      52 3 10 1 NaN

    • C

      52 NaN NaN 1 NaN

    • D

      52 3 10 NaN NaN

Unary plus (+)

1 card
  1. 23
    console.log(+"", +[], +[5], +[1, 2], +{}, +true);
    

    What is printed?

    • A

      0 NaN 5 12 NaN 1

    • B

      0 0 5 NaN 0 1

    • C

      0 0 5 NaN NaN 1

    • D

      NaN 0 5 NaN NaN 1

Equality (==)

2 cards
  1. 24

    Which of these comparisons is false?

    • A

      "0" == false

    • B

      null == 0

    • C

      "" == 0

    • D

      null == undefined

  2. 25
    console.log([1] == [1], [1] == 1, [1, 2] == "1,2");
    

    What is printed?

    • A

      false true true

    • B

      true false true

    • C

      false false false

    • D

      true true true

Array() constructor

1 card
  1. 26
    const a = new Array(3).map(() => "x");
    const b = Array.from({ length: 3 }, () => "x");
    console.log(a, b);
    

    What is printed?

    • A

      [ 3 ] [ 'x', 'x', 'x' ]

    • B

      [ 'x', 'x', 'x' ] [ 'x', 'x', 'x' ]

    • C

      [ undefined, undefined, undefined ] [ 'x', 'x', 'x' ]

    • D

      [ <3 empty items> ] [ 'x', 'x', 'x' ]

Array.prototype.fill()

1 card
  1. 27
    const groups = new Array(3).fill([]);
    groups[0].push("a");
    console.log(groups);
    

    What is printed?

    • A

      [ [ 'a' ], <2 empty items> ]

    • B

      [ [ 'a' ], [ 'a' ], [ 'a' ] ]

    • C

      [ [ 'a' ], [], [] ]

    • D

      Nothing: it throws TypeError because the array is frozen

for...in

1 card
  1. 28
    const list = [10, 20];
    for (const i in list) {
      console.log(typeof i, i + 1);
    }
    

    What is printed?

    • A

      number 1 then number 2

    • B

      number 11 then number 21

    • C

      string 11 then string 21

    • D

      string 01 then string 11

Array: length

1 card
  1. 29
    const list = [1, 2, 3];
    list.length = 1;
    list[3] = 4;
    console.log(list.length, list);
    

    What is printed?

    • A

      Nothing: assigning to length throws TypeError

    • B

      4 [ 1, <2 empty items>, 4 ]

    • C

      4 [ 1, undefined, undefined, 4 ]

    • D

      2 [ 1, 4 ]

Array.prototype.splice()

1 card
  1. 30
    const list = [1, 2, 3, 4];
    const out = list.splice(1, 2);
    console.log(list, out);
    

    What is printed?

    • A

      [ 1, 4 ] [ 2, 3 ]

    • B

      [ 1, 4 ] [ 1, 4 ]

    • C

      [ 2, 3 ] [ 1, 4 ]

    • D

      [ 1, 2, 3, 4 ] [ 2, 3 ]

Array.prototype.reduce()

1 card
  1. 31
    const total = [].reduce((sum, n) => sum + n);
    

    What happens?

    • A

      total is undefined

    • B

      total is 0

    • C

      total is NaN

    • D

      Throws TypeError: reduce of empty array with no initial value

Spread syntax (...)

1 card
  1. 32
    const original = { name: "Ada", tags: ["math"] };
    const copy = { ...original };
    copy.name = "Grace";
    copy.tags.push("code");
    console.log(original);
    

    What is printed?

    • A

      { name: 'Ada', tags: [ 'math', 'code' ] }

    • B

      { name: 'Grace', tags: [ 'math' ] }

    • C

      { name: 'Ada', tags: [ 'math' ] }

    • D

      { name: 'Grace', tags: [ 'math', 'code' ] }

Destructuring

1 card
  1. 33
    const { a = 1, b = 2, c = 3 } = { a: null, b: undefined };
    console.log(a, b, c);
    

    What is printed?

    • A

      1 undefined 3

    • B

      1 2 3

    • C

      null undefined 3

    • D

      null 2 3

Default parameters

1 card
  1. 34
    function area(w, h = w * 2) {
      return w * h;
    }
    console.log(area(3), area(3, undefined), area(3, null));
    

    What is printed?

    • A

      18 18 NaN

    • B

      18 18 0

    • C

      18 NaN 0

    • D

      18 18 18

Nullish coalescing operator (??)

1 card
  1. 35
    const settings = { retries: 0, label: "" };
    console.log(settings.retries || 3, settings.retries ?? 3, settings.label ?? "none");
    

    What is printed?

    • A

      3 3 none

    • B

      3 0 and then an empty string

    • C

      0 3 none

    • D

      0 0 none

Optional chaining (?.)

1 card
  1. 36
    const order = null;
    console.log(order?.customer.address.city);
    

    What is printed?

    • A

      null

    • B

      undefined

    • C

      Nothing: it is a SyntaxError to follow ?. with .

    • D

      Nothing: it throws TypeError reading address of undefined

Object.keys()

1 card
  1. 37
    const o = { b: 1, 2: 1, a: 1, 1: 1 };
    console.log(Object.keys(o));
    

    What is printed?

    • A

      [ '1', '2', 'b', 'a' ]

    • B

      [ '1', '2', 'a', 'b' ]

    • C

      [ 'b', '2', 'a', '1' ]

    • D

      [ 'b', 'a', '1', '2' ]

Map

1 card
  1. 38
    const m = new Map([[NaN, "n"], [{}, "o"]]);
    console.log(m.get(NaN), m.get({}));
    

    What is printed?

    • A

      undefined undefined

    • B

      n undefined

    • C

      undefined o

    • D

      n o

String.prototype.replace()

1 card
  1. 39
    console.log("a-b-c".replace("-", "+"));
    

    What is printed?

    • A

      a+b-c

    • B

      a-b-c

    • C

      a+b+c

    • D

      +

Number.prototype.toFixed()

1 card
  1. 40
    console.log((1.005).toFixed(2), (1.005).toFixed(2) === 1.01);
    

    What is printed?

    • A

      1.00 false

    • B

      1.00 true

    • C

      1.01 true

    • D

      1.01 false

String: length

1 card
  1. 41
    const s = "👍";
    console.log(s.length, [...s].length);
    

    What is printed?

    • A

      1 1

    • B

      4 1

    • C

      2 2

    • D

      2 1

Exponentiation (**)

1 card
  1. 42
    console.log(2 ** 3 ** 2);
    

    What is printed?

    • A

      64

    • B

      36

    • C

      Nothing: it is a SyntaxError without parentheses

    • D

      512

Date

1 card
  1. 43
    const d = new Date(2024, 1, 30);
    console.log(d.getMonth(), d.getDate());
    

    What is printed?

    • A

      Nothing: it throws RangeError for an invalid date

    • B

      2 1

    • C

      1 29

    • D

      1 30

try...catch

1 card
  1. 44
    function f() {
      try {
        return "try";
      } finally {
        return "finally";
      }
    }
    console.log(f());
    

    What is printed?

    • A

      try then finally

    • B

      finally

    • C

      Nothing: it is a SyntaxError to return inside finally

    • D

      try

function*

1 card
  1. 45
    function* g() {
      const x = yield 1;
      console.log("got", x);
    }
    const it = g();
    it.next("a");
    it.next("b");
    

    What is printed?

    • A

      got b

    • B

      got 1

    • C

      got undefined

    • D

      got a

End of deck · 45 cards

Save