SlideShare a Scribd company logo
LOGGING
IN JAVASCRIPT
PART 4
Record Timings:
You can record how long an operation took to complete
using console. You start a timer with console.time and
then end it with console.endTime
For example,
console.time('timer');
setTimeout(() => console.log, 1000);
console.timeEnd('timer');
// timer: 0.1239453125ms
Note: Passing the label in console.time is optional. If
you use a label with console.time you must pass-in that
same label when calling console.timeEnd.
Grouping Logs:
You can group the console messages together with
console. Use console.group and console.groupEnd to group
console messages together.
For example,
console.group('Even Numbers');
console.log(2);
console.log(4);
console.log(6)
console.groupEnd('Even Numbers');
Output:
Nested Grouping of Logs:
Groups can also be nested to another one.
Take a look at the below example,
console.group('Even');
console.log('2');
console.log('4');
console.group('Odd');
console.log('1');
console.log('2');
console.groupEnd();
console.log('6');
console.groupEnd();
Output:
Styling your Logs:
Console logging can be styled using the delimiter %c.
The first argument is the message to be displayed.
Everything that comes after the first %c will be styled
by the string provided by the second argument, then
everything after the next %c is styled by the following
string argument, and so on.
console.log(
'Hello %cJSNugget%c!',
'color: #008f68; font-weight: bold; font-size: 1rem',
'color: hotpink; font-weight: bold; font-size: 1rem;'
);
Output:

More Related Content

More from Ideas2IT Technologies (20)

PDF
Version comaparison in JavaScript
Ideas2IT Technologies
 
PDF
Currying in JavaScript
Ideas2IT Technologies
 
PDF
JS Testing Frameworks
Ideas2IT Technologies
 
PDF
Cool usage of Encoding and Decoding a URI in Javascript
Ideas2IT Technologies
 
PDF
Iterables and Iterators in JavaScript
Ideas2IT Technologies
 
PDF
String comparison in javascript
Ideas2IT Technologies
 
PDF
JavaScript symbols
Ideas2IT Technologies
 
PDF
Json.parse() in JavaScript
Ideas2IT Technologies
 
PDF
Bubble sort in Java Script
Ideas2IT Technologies
 
PDF
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
PDF
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
PDF
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
PDF
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
PDF
Variable hoisting in JavaScript
Ideas2IT Technologies
 
PDF
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
PDF
Logging in JavaScript - part-2
Ideas2IT Technologies
 
PDF
Logging in JavaScript - part-1
Ideas2IT Technologies
 
PDF
Array vs set in JavaScript
Ideas2IT Technologies
 
PDF
Arguments Object in JavaScript
Ideas2IT Technologies
 
Version comaparison in JavaScript
Ideas2IT Technologies
 
Currying in JavaScript
Ideas2IT Technologies
 
JS Testing Frameworks
Ideas2IT Technologies
 
Cool usage of Encoding and Decoding a URI in Javascript
Ideas2IT Technologies
 
Iterables and Iterators in JavaScript
Ideas2IT Technologies
 
String comparison in javascript
Ideas2IT Technologies
 
JavaScript symbols
Ideas2IT Technologies
 
Json.parse() in JavaScript
Ideas2IT Technologies
 
Bubble sort in Java Script
Ideas2IT Technologies
 
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
Variable hoisting in JavaScript
Ideas2IT Technologies
 
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
Logging in JavaScript - part-2
Ideas2IT Technologies
 
Logging in JavaScript - part-1
Ideas2IT Technologies
 
Array vs set in JavaScript
Ideas2IT Technologies
 
Arguments Object in JavaScript
Ideas2IT Technologies
 

Recently uploaded (20)

PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
65811_Introducing the Fusion AI Agent Studio (1).pdf
g6129590
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
PPTX
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
PPTX
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PDF
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
65811_Introducing the Fusion AI Agent Studio (1).pdf
g6129590
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
Ad

Logging in JavaScript - Part-4

  • 2. Record Timings: You can record how long an operation took to complete using console. You start a timer with console.time and then end it with console.endTime For example, console.time('timer'); setTimeout(() => console.log, 1000); console.timeEnd('timer'); // timer: 0.1239453125ms Note: Passing the label in console.time is optional. If you use a label with console.time you must pass-in that same label when calling console.timeEnd.
  • 3. Grouping Logs: You can group the console messages together with console. Use console.group and console.groupEnd to group console messages together. For example, console.group('Even Numbers'); console.log(2); console.log(4); console.log(6) console.groupEnd('Even Numbers'); Output:
  • 4. Nested Grouping of Logs: Groups can also be nested to another one. Take a look at the below example, console.group('Even'); console.log('2'); console.log('4'); console.group('Odd'); console.log('1'); console.log('2'); console.groupEnd(); console.log('6'); console.groupEnd(); Output:
  • 5. Styling your Logs: Console logging can be styled using the delimiter %c. The first argument is the message to be displayed. Everything that comes after the first %c will be styled by the string provided by the second argument, then everything after the next %c is styled by the following string argument, and so on. console.log( 'Hello %cJSNugget%c!', 'color: #008f68; font-weight: bold; font-size: 1rem', 'color: hotpink; font-weight: bold; font-size: 1rem;' ); Output: