parseInt()
1 card- 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 ]
- A
typeof
1 card- 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
- A
Number
1 card- 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
- A
Array.prototype.includes()
1 card- 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
- A
Array.prototype.sort()
1 card- 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 ]
- A
var
1 card- 06
function f() { console.log(x); var x = 1; console.log(x); } f();What happens?
- A
Throws
ReferenceErroron the firstconsole.log - B
Prints
null, then1 - C
Prints
1, then1 - D
Prints
undefined, then1
- A
let
1 card- 07
function f() { console.log(x); let x = 1; } f();What happens?
- A
Prints
undefined - B
Throws
ReferenceError:xis in the temporal dead zone - C
Prints
null - D
Throws
SyntaxError:xis used before it is declared
- A
Closures
1 card- 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
- A
this
1 card- 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 ofundefined - B
Returns
1;counter.countis now1 - C
Returns
NaN - D
Returns
1, butcounter.countstays0
- A
Arrow function expressions
1 card- 10
const Point = (x, y) => ({ x, y }); const p = new Point(1, 2);What happens on the second line?
- A
pisundefined - B
pis{ x: 1, y: 2 } - C
Throws
TypeError:Pointis not a constructor - D
pis an empty object: the return value of an arrow is ignored bynew
- A
Using microtasks in JavaScript
1 card- 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
- A
Promise
1 card- 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, sobis skipped - C
b a - D
a b
- A
async function
1 card- 13
async function f() { return 1; } console.log(f());What is printed?
- A
Promise { 1 } - B
1 - C
undefined - D
Promise { <pending> }
- A
await
1 card- 14
async function f() { console.log("a"); await null; console.log("b"); } f(); console.log("c");What is printed?
- A
a c—bis never printed becausenullis not a promise - B
c a b - C
a b c - D
a c b
- A
Promise.all()
2 cards- 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
runreturns before them - B
About 600 ms
- C
About 100 ms
- D
About 300 ms
- A
- 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' ]
- A
Promise.prototype.then()
1 card- 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
- A
const
1 card- 18
const list = [1]; list.push(2); list = [];What happens?
- A
pushthrowsTypeError:listis constant - B
Both lines succeed;
listends up as[] - C
pushsucceeds; the reassignment throwsTypeError - D
Both lines throw
- A
Object.freeze()
1 card- 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
- A
JSON.stringify()
1 card- 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
TypeErrorbecause a function cannot be serialised - C
{"a":null,"b":null,"c":null,"d":[null]} - D
{"c":"NaN","d":[]}
- A
Symbol
1 card- 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"}
- A
Addition (+)
1 card- 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
- A
Unary plus (+)
1 card- 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
- A
Equality (==)
2 cards- 24
Which of these comparisons is false?
- A
"0" == false - B
null == 0 - C
"" == 0 - D
null == undefined
- A
- 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
- A
Array() constructor
1 card- 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' ]
- A
Array.prototype.fill()
1 card- 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
TypeErrorbecause the array is frozen
- A
for...in
1 card- 28
const list = [10, 20]; for (const i in list) { console.log(typeof i, i + 1); }What is printed?
- A
number 1thennumber 2 - B
number 11thennumber 21 - C
string 11thenstring 21 - D
string 01thenstring 11
- A
Array: length
1 card- 29
const list = [1, 2, 3]; list.length = 1; list[3] = 4; console.log(list.length, list);What is printed?
- A
Nothing: assigning to
lengththrowsTypeError - B
4 [ 1, <2 empty items>, 4 ] - C
4 [ 1, undefined, undefined, 4 ] - D
2 [ 1, 4 ]
- A
Array.prototype.splice()
1 card- 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 ]
- A
Array.prototype.reduce()
1 card- 31
const total = [].reduce((sum, n) => sum + n);What happens?
- A
totalisundefined - B
totalis0 - C
totalisNaN - D
Throws
TypeError: reduce of empty array with no initial value
- A
Spread syntax (...)
1 card- 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' ] }
- A
Destructuring
1 card- 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
- A
Default parameters
1 card- 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
- A
Nullish coalescing operator (??)
1 card- 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 0and then an empty string - C
0 3 none - D
0 0 none
- A
Optional chaining (?.)
1 card- 36
const order = null; console.log(order?.customer.address.city);What is printed?
- A
null - B
undefined - C
Nothing: it is a
SyntaxErrorto follow?.with. - D
Nothing: it throws
TypeErrorreadingaddressofundefined
- A
Object.keys()
1 card- 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' ]
- A
Map
1 card- 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
- A
String.prototype.replace()
1 card- 39
console.log("a-b-c".replace("-", "+"));What is printed?
- A
a+b-c - B
a-b-c - C
a+b+c - D
+
- A
Number.prototype.toFixed()
1 card- 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
- A
String: length
1 card- 41
const s = "👍"; console.log(s.length, [...s].length);What is printed?
- A
1 1 - B
4 1 - C
2 2 - D
2 1
- A
Exponentiation (**)
1 card- 42
console.log(2 ** 3 ** 2);What is printed?
- A
64 - B
36 - C
Nothing: it is a
SyntaxErrorwithout parentheses - D
512
- A
Date
1 card- 43
const d = new Date(2024, 1, 30); console.log(d.getMonth(), d.getDate());What is printed?
- A
Nothing: it throws
RangeErrorfor an invalid date - B
2 1 - C
1 29 - D
1 30
- A
try...catch
1 card- 44
function f() { try { return "try"; } finally { return "finally"; } } console.log(f());What is printed?
- A
trythenfinally - B
finally - C
Nothing: it is a
SyntaxErrortoreturninsidefinally - D
try
- A
function*
1 card- 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
- A
End of deck · 45 cards