LearnFrenzy
Sign in Take a free test

Conditional Statements · Exercise 1 of 4

Conditional Statements Conditional Statements MCQ

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on JavaScript conditionals: if and else-if, truthy conditions, the dangling else, the ternary operator, switch matching and fall-through, default, switch (true), guard clauses and lookup tables. Pick an option to check your answer instantly.

Question 11 Medium

What is a guard clause?

A A try/catch around a condition
B A default case in a switch
C A condition that is checked twice
D An early return or throw at the start of a function that handles invalid or special cases
Question page & discussion
Question 12 Medium

When is an object lookup like PRICES[size] ?? 0 a better choice than a switch?

A When each case must test a range
B When the cases must fall through
C Never; lookups are slower than switch
D When each case only maps an input value to an output value
Question page & discussion
Question 13 Medium

What does if (x = 5) { … } do?

A Assigns 5 to x; the condition is 5, which is truthy, so the block runs
B Compares x with 5
C Throws a SyntaxError
D Runs the block only if x was already 5
Question page & discussion
Question 14 Easy

user is undefined. What happens with if (user?.isAdmin) { … }?

A The condition is undefined (falsy), so the block is skipped without an error
B A TypeError is thrown
C The block runs
D A ReferenceError is thrown
Question page & discussion
Question 15 Hard

Why does case NaN: never match, even when the switch value is NaN?

A switch uses ===, and NaN === NaN is false
B NaN cannot be written in a case
C switch converts NaN to 0
D It does match, but only in strict mode
Question page & discussion
Up next · Exercise 2Predict the Output20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links