Final exam
JavaScript for Beginners
Before you start
- 20 questions, drawn at random from a pool of 33.
- Pass mark: 70%. Your final score is 30% practice + 70% exam.
- No time limit, but finish within 3 hours. You can move between questions before you submit.
- Failed? Review the lessons and try again: every attempt gets a new set of questions.
Question 1 of 20Choose one
Which statement prints the text Ready to the browser console?
Question 2 of 20True or false
A line that starts with // is ignored by JavaScript.
Question 3 of 20Choose one
Each declaration below is followed by the line rate = 0.07;. Which declaration makes that line throw an error?
Question 4 of 20Fill in the blanks
Fill in the blanks
typeof 3.5 is and typeof "3.5" is .
Question 5 of 20Choose one
What is "JavaScript".length?
Question 6 of 20Work it out
What is the value of 20 % 6?
Question 7 of 20Choose one
What does "3" * "4" evaluate to?
Question 8 of 20Sort into groups
Is each comparison true or false?
Tap an item, then tap its group (or drag it there).
Question 9 of 20Choose one
With const x = 3;, which condition is true only when x is either 1 or 2?
Question 10 of 20Select all that apply
Which values make if (value) { ... } skip its block? Select all that apply.
Select all that apply.
Question 11 of 20Choose one
What is the value of result?
``js
const temp = 15;
const result = temp > 25 ? "hot" : temp > 10 ? "mild" : "cold";
``
Question 12 of 20Choose one
What does sum(2) return?
``js
function sum(a, b = 10) {
return a + b;
}
``
Question 13 of 20True or false
An arrow function with a single expression and no curly braces returns that expression's value automatically.
Question 14 of 20Spot the mistake
This function should return the larger of two numbers. Find the line with the bug.
Question 15 of 20Choose one
What happens when this code runs?
``js
function setup() {
const limit = 5;
}
setup();
console.log(limit);
``
Question 16 of 20Work it out
How many times does "tick" print?
``js
for (let i = 3; i < 12; i += 3) {
console.log("tick");
}
``
Question 17 of 20Choose one
Which loop prints every item of const colors = ["red", "green", "blue"] without using an index?
Question 18 of 20What would you do?
What would you do?
A loop is supposed to add up the prices in an array, but the total always equals only the final price. What is the likely cause?
Question 19 of 20Choose one
After const a = [5, 10, 15]; runs a.push(20); a.shift();, what is a?
Question 20 of 20Choose one
What does [4, 9, 16].map(Math.sqrt) return?
Question 21 of 20Work it out
What does [1, 2, 3, 4].reduce((acc, n) => acc + n * n, 0) return?
Question 22 of 20Choose one
How do you sort const nums = [25, 100, 3] into ascending numeric order?
Question 23 of 20Match the pairs
Match each array method to what it returns.
Tap an answer, then tap the place where it belongs (or drag it there).
- filter
- find
- includes
- indexOf
Question 24 of 20Choose one
Given const book = { title: "Dune", author: { name: "Frank" } };, which expression returns "Frank"?
Question 25 of 20Fill in the blanks
Fill in the blanks
Object.keys({ a: 1, b: 2, c: 3 }) returns an array with items, and JSON.stringify({ a: 1 }) returns a value of type .
Question 26 of 20True or false
const arr = [1, 2]; arr.push(3); throws an error because arr is a const.
Question 27 of 20Choose one
Which line safely shows a user's comment on the page without running any HTML it contains?
Question 28 of 20Choose one
What is wrong with button.addEventListener("click", save());?
Question 29 of 20Choose one
In a form's submit listener, why call event.preventDefault()?
Question 30 of 20Match the pairs
Match each error message to its most likely cause.
Tap an answer, then tap the place where it belongs (or drag it there).
- ReferenceError: totl is not defined
- TypeError: Cannot read properties of null
- SyntaxError: Unexpected end of input
- TypeError: price.toFixed is not a function
Question 31 of 20True or false
Code inside a catch block runs only if an error is thrown in the matching try block.
Question 32 of 20Put in order
In what order are the messages logged?
``js
console.log("start");
setTimeout(() => console.log("timer"), 0);
Promise.resolve().then(() => console.log("promise"));
console.log("end");
``
Drag the items, or use the arrow buttons, to put them in order.
- end
- promise
- timer
- start
Question 33 of 20What would you do?
What would you do?
Your async function calls await fetch(url) and the server responds with 500 Internal Server Error. Your try...catch never runs. Why?