JavaScript mock tests
Test yourself on the whole course, against the clock: questions from every module, then coding problems you solve and run right here. Your score comes at the end, with every answer explained.
Each mock test has 12 questions drawn from the lessons and up to 3 coding problems, and 45 minutes on the clock, which keeps running if you reload. Questions are worth a point each, and each coding problem 4 points, shared by its tests. Score 60% or more to pass; your best score is kept.
- 01Mock test 112 questions · 3 coding problems · 45 minutes · 24 points
- 02Mock test 212 questions · 3 coding problems · 45 minutes · 24 points
- 03Mock test 312 questions · 3 coding problems · 45 minutes · 24 points
Part A · 12 questions
- What does [5, 10, 15].reduce((a, b) => a + b, 0) return?
- How do you write 1,00,000 rupees the Indian way?
- Are total and Total the same variable?
- How do you count the properties of an object obj?
- Which call adds the class "open" if it's missing and removes it if present?
- How do you call a static method count on the class Ticket?
- Why is the simple recursive Fibonacci slow?
- What is the GCD of 48 and 36?
- What is 0 || 10?
- Which arguments does forEach pass to its callback?
- What is the difference between slice and splice?
- Which reads the property stored in the variable key from obj?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1Fibonacci, fastHard · 4 points
Write
fib(n)(0, 1, 1, 2, 3, 5...) recursively, but remember results in aMapsofib(70)returns instantly.Expected output55 190392490709135
Loading the editor… - 2Count the pricesMedium · 4 points
Write the number of elements with the class
priceinto the#countspan.Your page should- The count shows 3
Loading the editor… - 3Count with a MapMedium · 4 points
Read a line of words and log how many times each appears, in first-seen order, as
word: count, using aMap.Inputthe cat and the hat
Expected outputthe: 2 cat: 1 and: 1 hat: 1
Loading the editor…
Part A · 12 questions
- What is the difference between call and apply?
- Two independent requests each take 1 second. Roughly how long does await Promise.all([...]) take?
- Which is a correct arrow with no parameters?
- Why call e.preventDefault() in a form's submit handler?
- What does <script type="module"> allow?
- What does super.describe() do inside a child's describe method?
- Why does setTimeout(f, 0) still run after the code that follows it?
- How does switch compare the value with each case?
- What does setTimeout(fn, 1000) do?
- When does a finally block run?
- What is 0 ?? 10?
- How many times does for (let i = 0; i < 4; i++) run its body?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1Add until zeroMedium · 4 points
Read numbers, one per line, until a
0is read. Log their total. Use ado...whileloop.Input5 3 0
Expected output8
Loading the editor… - 2The fastest winsMedium · 4 points
Use
Promise.raceto log whichever of the two waits finishes first.Expected outputfast
Loading the editor… - 3Sort numbers properlyMedium · 4 points
sort()puts10before2. Give it an arrow-function comparator so the numbers sort from smallest to largest.Input10 2 1 33
Expected output[ 1, 2, 10, 33 ]
Loading the editor…
Part A · 12 questions
- What does for (const x of ["a", "b"]) give you in x?
- What does age >= 18 ? "adult" : "minor" give when age is 16?
- What does 17 % 5 evaluate to?
- Where should you put .catch in a chain of .then calls?
- What does for...in loop over in an object?
- What does JSON.stringify({a: 1}) return?
- After const copy = { ...obj }, which change also changes obj?
- What does typeof null return?
- Reading user.name when user is undefined throws which error?
- Which comparison is false?
- Why can't a plain object use two different objects as keys?
- What does const add = (a, b) => { a + b }; return for add(1, 2)?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1Error-first callbacksHard · 4 points
Write
divide(a, b, callback). Ifbis 0, callcallbackwith anErrorwhose message isdivide by zero; otherwise call it withnulland the result.Expected output2.5 Error: divide by zero
Loading the editor… - 2this in a class callbackHard · 4 points
counter.clickis handed torunas a callback and losesthis. Fix the class by turningclickinto an arrow-function class field, so the program logs2.Expected output2
Loading the editor… - 3Distance between two pointsHard · 4 points
Read four numbers,
x1,y1,x2andy2, one per line. Log the straight-line distance between the points with two decimal places.Input0 0 3 4
Expected output5.00
Loading the editor…