Bird
Raised Fist0
Node.jsframework~20 mins

Console methods beyond log in Node.js - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Console Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of console.count usage
What will be printed to the console after running this Node.js code snippet?
Node.js
console.count('label');
console.count('label');
console.count('other');
console.count('label');
A
label: 1
label: 2
other: 1
label: 3
B
label: 1
label: 1
other: 1
label: 1
C
label: 1
label: 2
other: 2
label: 3
D
label: 0
label: 1
other: 0
label: 2
Attempts:
2 left
💡 Hint
console.count keeps track of how many times a label has been counted.
Predict Output
intermediate
2:00remaining
Behavior of console.assert with false condition
What will be the output when running this Node.js code?
Node.js
console.assert(false, 'Assertion failed!');
console.assert(true, 'This will not show');
AAssertion failed!
BNo output
CError: Assertion failed!
D
Assertion failed!
This will not show
Attempts:
2 left
💡 Hint
console.assert only prints the message if the first argument is false.
Predict Output
advanced
2:00remaining
Output of console.group and console.groupEnd
What will be the console output of this Node.js code snippet?
Node.js
console.log('Start');
console.group('Group 1');
console.log('Inside group');
console.groupEnd('Group 1');
console.log('End');
A
Start
Group 1
Inside group
End
B
Start
  Group 1
  Inside group
End
C
Start
Inside group
End
D
Start
Group 1
  Inside group
End
Attempts:
2 left
💡 Hint
console.group indents the following logs until console.groupEnd is called.
Predict Output
advanced
2:00remaining
Effect of console.time and console.timeEnd
What will this Node.js code print to the console?
Node.js
console.time('timer');
setTimeout(() => {
  console.timeEnd('timer');
}, 100);
Atimer: 100ms
Btimer: <some number close to 100>ms
Ctimer: 0ms
DError: No such label 'timer'
Attempts:
2 left
💡 Hint
console.timeEnd prints the elapsed time since console.time was called with the same label.
lifecycle
expert
3:00remaining
Understanding console.trace output
What does the following Node.js code output when executed?
Node.js
function a() {
  b();
}
function b() {
  c();
}
function c() {
  console.trace('Trace here');
}
a();
A
Trace here
    at c (&lt;anonymous&gt;)
B
Trace here
    at a (&lt;anonymous&gt;)
    at b (&lt;anonymous&gt;)
    at c (&lt;anonymous&gt;)
C
Trace here
    at c (&lt;anonymous&gt;)
    at b (&lt;anonymous&gt;)
    at a (&lt;anonymous&gt;)
    at &lt;anonymous&gt;
D
Trace here
    at b (&lt;anonymous&gt;)
    at c (&lt;anonymous&gt;)
    at a (&lt;anonymous&gt;)
Attempts:
2 left
💡 Hint
console.trace prints the call stack from the point it is called.

Practice

(1/5)
1. Which console method is best to display an error message in Node.js?
easy
A. console.warn()
B. console.error()
C. console.info()
D. console.debug()

Solution

  1. Step 1: Understand the purpose of console methods

    console.error() is designed to show error messages clearly, often in red or highlighted in terminals.
  2. Step 2: Compare with other methods

    console.warn() shows warnings, console.info() shows informational messages, and console.debug() is for debugging details, not errors.
  3. Final Answer:

    console.error() -> Option B
  4. Quick Check:

    Error messages = console.error() [OK]
Hint: Errors use console.error() to stand out clearly [OK]
Common Mistakes:
  • Using console.log() for errors
  • Confusing console.warn() with error
  • Using console.info() for error messages
2. Which of the following is the correct syntax to start a timer named 'loadTime' using console methods?
easy
A. console.time('loadTime');
B. console.startTimer('loadTime');
C. console.timer('loadTime');
D. console.begin('loadTime');

Solution

  1. Step 1: Recall the correct console method for timing

    The method to start a timer is console.time(), which takes a label string.
  2. Step 2: Check the syntax of options

    Only console.time('loadTime'); matches the correct method and syntax.
  3. Final Answer:

    console.time('loadTime'); -> Option A
  4. Quick Check:

    Start timer = console.time() [OK]
Hint: Start timers with console.time('label') exactly [OK]
Common Mistakes:
  • Using console.startTimer() which doesn't exist
  • Using console.timer() instead of console.time()
  • Missing parentheses or quotes
3. What will be the output of the following Node.js code?
console.group('Fruits');
console.log('Apple');
console.log('Banana');
console.groupEnd('Fruits');
medium
A. A grouped console output with label 'Fruits' containing 'Apple' and 'Banana' indented
B. An error because console.groupEnd() does not take arguments
C. Just prints 'Apple' and 'Banana' without grouping
D. Prints 'Fruits' then 'Apple' and 'Banana' on the same line

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]
Hint: 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
4. Identify the error in this Node.js code snippet:
console.time('process');
// some code
console.timeEnd();
medium
A. console.time() cannot be used without console.timeLog()
B. console.timeEnd() should be called before console.time()
C. Missing label argument in console.timeEnd()
D. No error, code is correct

Solution

  1. Step 1: Check console.time and console.timeEnd usage

    console.time() starts a timer with a label. console.timeEnd() must be called with the same label to stop and print the timer.
  2. Step 2: Identify the mistake in the code

    console.timeEnd() is called without the label 'process', so it will throw an error or not work as expected.
  3. Final Answer:

    Missing label argument in console.timeEnd() -> Option C
  4. Quick Check:

    console.timeEnd() needs matching label [OK]
Hint: Always pass the same label to console.timeEnd() as console.time() [OK]
Common Mistakes:
  • Calling console.timeEnd() without label
  • Calling console.timeEnd() before console.time()
  • Assuming console.timeLog() is mandatory
5. You want to display an array of user objects as a neat table in the console. Which console method should you use to achieve this?
hard
A. console.group(users);
B. console.log(users);
C. console.dir(users);
D. console.table(users);

Solution

  1. Step 1: Understand console.table() purpose

    console.table() displays arrays or objects as formatted tables, making data easier to read.
  2. Step 2: Compare with other methods

    console.group() groups logs, console.dir() shows object details, and console.log() prints raw data without table formatting.
  3. Final Answer:

    console.table(users); -> Option D
  4. Quick Check:

    Display arrays as tables = console.table() [OK]
Hint: Use console.table() to show arrays or objects as tables [OK]
Common Mistakes:
  • Using console.log() which shows raw array
  • Using console.group() which groups logs but no table
  • Confusing console.dir() with table display