0
0
Node.jsframework~20 mins

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

Choose your learning style9 modes available
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.