Bird
0
0

What will be the output of this JSON string parsed in JavaScript?

medium📝 Predict Output Q4 of 15
Rest API - Request and Response Format
What will be the output of this JSON string parsed in JavaScript?
const jsonString = '{"active": true, "count": 5}';
const obj = JSON.parse(jsonString);
console.log(obj.active && obj.count > 3);
Afalse
Btrue
Cundefined
DError
Step-by-Step Solution
Solution:
  1. Step 1: Parse JSON string to object

    JSON.parse converts the string to an object with active: true and count: 5.
  2. Step 2: Evaluate the logical expression

    obj.active is true, obj.count > 3 is true, so true && true = true.
  3. Final Answer:

    true -> Option B
  4. Quick Check:

    Logical expression result = true [OK]
Quick Trick: JSON.parse converts strings to usable JavaScript objects [OK]
Common Mistakes:
  • Assuming JSON.parse returns a string
  • Confusing logical AND results
  • Expecting an error from valid JSON

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes