Quiz: Predict the Output (Basics)
Time to Put It All Together
You've worked through variables, operators, functions, arrays, objects, destructuring, strings, error handling, and modules. Now let's see how well those concepts actually stuck.
This isn't about memorizing syntax. It's about having a mental model of how JavaScript evaluates code, step by step. Each question below is something you could genuinely encounter in real code. No trick questions for the sake of being tricky — every one tests a concept that matters.
How to use this quiz: Read each snippet, trace the execution in your head (or on paper), pick your answer, then read the explanation carefully — even if you got it right. The explanations connect back to the "why" behind the behavior.
- 1Trace line by line, never skip ahead or assume
- 2Pay attention to var vs let vs const — they hoist differently
- 3When you see +, ask: are both operands numbers? If not, expect string concatenation
- 4Function declarations are hoisted entirely, function expressions are not
- 5Objects and arrays are references — copying a variable copies the pointer, not the data
Question 1: The Warm-Up
let x = 10;
let y = "5";
console.log(x + y);
console.log(x - y);
Question 2: Hoisting Surprise
console.log(a);
console.log(b);
var a = 5;
let b = 10;
Question 3: Function Hoisting
console.log(greet());
console.log(hello());
function greet() {
return "Hi!";
}
var hello = function () {
return "Hello!";
};
Question 4: Scope Boundaries
for (var i = 0; i < 3; i++) {
// loop body
}
console.log(i);
for (let j = 0; j < 3; j++) {
// loop body
}
console.log(j);
Checkpoint: How's It Going?
Four questions down. If you got at least 3 right, your fundamentals are solid. If hoisting tripped you up, that's completely normal — it trips up experienced developers too. The key insight is: declarations are hoisted, assignments are not, and let/const have a temporal dead zone that var does not.
Question 5: Array Methods and Return Values
const nums = [1, 2, 3, 4, 5];
const result = nums.filter(n => n > 2).map(n => n * 10);
console.log(result);
console.log(nums);
Question 6: Object References
const person = { name: "Alice", age: 25 };
const copy = person;
copy.name = "Bob";
console.log(person.name);
console.log(copy.name);
Question 7: Destructuring with Defaults
const config = { theme: "dark", lang: undefined };
const { theme, lang = "en", debug = false } = config;
console.log(theme);
console.log(lang);
console.log(debug);
Question 8: Template Literal Expressions
const a = 10;
const b = 20;
console.log(`Sum: ${a + b}`);
console.log("Sum: " + a + b);
Checkpoint: Halfway There
Eight questions in. If you nailed 6 or more, you're building strong instincts. The next four questions ramp up the difficulty. They combine multiple concepts — exactly the kind of code you will see in production.
Question 9: The typeof Quirk
console.log(typeof null);
console.log(typeof undefined);
console.log(typeof NaN);
Question 10: Error Handling Flow
function divide(a, b) {
try {
if (b === 0) throw new Error("Cannot divide by zero");
return a / b;
} catch (err) {
console.log(err.message);
return -1;
} finally {
console.log("done");
}
}
console.log(divide(10, 0));
Question 11: Spread and Shallow Copy
const original = { a: 1, b: { c: 2 } };
const clone = { ...original };
clone.a = 99;
clone.b.c = 99;
console.log(original.a);
console.log(original.b.c);
Question 12: Putting It All Together
var count = 0;
function increment() {
count++;
return count;
}
const results = [increment(), increment(), increment()];
const doubled = results.map(n => n * 2);
const [first, ...rest] = doubled;
console.log(first);
console.log(rest);
console.log(count);
Scoring Guide
| Score | Assessment |
|---|---|
| 11-12 | Excellent. Your JavaScript fundamentals are rock solid. You are ready for the deep dive module. |
| 8-10 | Strong foundation with a few gaps. Re-read the explanations for the ones you missed — those are the exact areas to strengthen. |
| 5-7 | You have the basics but some concepts need more practice. Revisit the specific topics that tripped you up before moving on. |
| 0-4 | Go back through the fundamentals module. Focus on tracing code line by line instead of guessing. The mental model section at the top is your friend. |
No matter your score, remember: understanding the why behind the behavior matters more than getting the right answer by instinct. Every question you missed is a concept you just learned more deeply by reading the explanation.