Bird
0
0

What will be the output of the following Node.js code?

medium📝 component behavior Q13 of 15
Node.js - Debugging and Profiling
What will be the output of the following Node.js code?
console.group('Fruits');
console.log('Apple');
console.log('Banana');
console.groupEnd('Fruits');
AA grouped console output with label 'Fruits' containing 'Apple' and 'Banana' indented
BAn error because console.groupEnd() does not take arguments
CJust prints 'Apple' and 'Banana' without grouping
DPrints 'Fruits' then 'Apple' and 'Banana' on the same line
Step-by-Step Solution
Solution:
  1. Step 1: Understand console.group and console.groupEnd behavior

    console.group() starts a new indented group in the console output. console.groupEnd() ends the current group.
  2. Step 2: Analyze the code output

    The logs 'Apple' and 'Banana' appear indented under the group labeled 'Fruits'. Passing 'Fruits' to console.groupEnd() is ignored and does not cause error.
  3. Final Answer:

    A grouped console output with label 'Fruits' containing 'Apple' and 'Banana' indented -> Option A
  4. Quick Check:

    console.group() indents logs until groupEnd() [OK]
Quick Trick: console.group() indents logs until console.groupEnd() [OK]
Common Mistakes:
  • Thinking console.groupEnd() requires argument
  • Expecting error due to argument in groupEnd
  • Ignoring indentation effect of console.group

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes