Question Bank
JavaScript Control Flow and Conditional Quiz
Difficulty: Easy
Read JavaScript's small but treacherous control-flow rules: switch fall-through, ASI biting return statements, and short-circuit logical chains.
JavaScript Control Flow and Conditional Quiz
Read JavaScript's small but treacherous control-flow rules: switch fall-through, ASI biting return statements, and short-circuit logical chains.
Question Bank
Easy
JavaScript
3 questions
quiz
conditionals
loops
fundamentals
753 views
22
Implement getRange(n) with a single switch so that 1-3 -> 'Low', 4-6 -> 'Mid', 7-9 -> 'High', anything else -> 'Not in range!'. Use case fall-through.
Examples
Example 1:
Input: getRange(6), getRange(8), getRange(12)
Output: 'Mid', 'High', 'Not in range!'
Explanation: Stacking case labels without a `break` lets multiple values share a single block. The `default` clause catches everything else.Predict what greet() returns and explain how automatic semicolon insertion (ASI) bit it.
Examples
Example 1:
Input: function greet() { return\n { message: 'hello' } }; greet()
Output: undefined
Explanation: ASI inserts a semicolon after `return`, so the function returns `undefined` and the object literal becomes unreachable code.Predict the result of each short-circuit expression. Cover && and || plus the nullish coalescing ?? operator.
Examples
Example 1:
Input: 0 || 'fallback', 0 ?? 'fallback', null || 'a' || 'b', false && 'never'
Output: 'fallback', 0, 'a', false
Explanation: `||` returns the first truthy operand (or last); `??` only falls back on `null` / `undefined`; `&&` short-circuits on the first falsy operand.