Skip to content

Advanced JavaScript logging

Grouping

To group similar log statements, you can use console.group([groupName]) and console.groupEnd():

console.group("URL Details");
console.log("Scheme: HTTPS")
console.log("Host: example.com");
console.groupEnd();

Resulting in this output:

► URL Details

The same, but expanded:

▼ URL Details
    Scheme: HTTPS
    Host: example.com

Tables

Usually, a listing of array objects looks like this:

var languages = [
    { name: "JavaScript", fileExtension: ".js" },
    { name: "TypeScript", fileExtension: ".ts" },
    { name: "CoffeeScript", fileExtension: ".coffee" }
];

console.log(languages);

And the same using console.table():

var languages = [
    { name: "JavaScript", fileExtension: ".js" },
    { name: "TypeScript", fileExtension: ".ts" },
    { name: "CoffeeScript", fileExtension: ".coffee" }
];

console.table(languages);

(source)

(source)

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.