Console.What?!?

Daniel C Reyes
2 min readJan 10, 2021

The world beyond Console.log in JavaScript.

As I continue to build projects in JavaScript I have always looked back at my code and realized that I had left at the minimum 5 console.logs in an attempt to find that annoying bug. What i didn’t know was that console has more than properties then log. Down below I will go thru three of the what I thought were the most useful and fun properties of Console.

Console.count();

The Count property of Console keeps count of how many times it has been called. It is mostly used to check if functions are being called when I expect them to. You can provide it with a string as a parameter. It will serve as the label.

let user= '';
const friends= (user) => {
console.count('followers');
return `${user} is following you`;
}
friends('Oliver'); =>followers: 1
friends('Charlie');=>followers: 2
friends('Gloria'); =>followers: 3

Console.assert();

This function writes to the console if the statement is false. It will not show it if the statement is true. Console.assert () can take two parameters. The first parameter is what it will make the check on if true or false. The second one is the error message you want to display.

const twenty= (X, Y) => {
console.assert(X + Y === 20, 'does not equal 20');
};

twenty(2,2); => false: does not equal 20
twenty(10,10); => true:
twenty(15,5); => true:

Console.table();

Console.table which without a doubt is my favorite is a function that displays your arrays and objects in a neat and nice table table. Console.table takes in two parameters, the data, and the names in an array of the columns you wish to display . Every element, or property, will correspond to a row in the table.

const data= [1, 2, 3, 4, 5];
const user= {
name: "Oliver",
lastName: "Reyes",
twitterHandle: "OlliesDogDays",
};
console.table(data);
console.table(data)
console.table(user)

Hope these new Console properties are helpful!

--

--