Complete Guide on JavaScript Console.log()

Complete guide on console.log

If you ever worked on developing web application with JavaScript, You will be familiar with console.log() Console.log is a function that is commonly used in JavaScript programming. It allows developers to output messages to the browser’s console, providing a way to troubleshoot and debug their code.

The syntax for using console.log is relatively simple. Simply type “console.log” followed by a set of parentheses and the message you want to output within the parentheses. Running the following code, you will find there is so much going on in the console.

console.log( console );

The console message will be 👇

log the console object.

In this blog we will briefly talk about top tricks in the console method.

Log

the most used method. It prints the message in the console. Useful when debugging & testing.

console.log("Hello World");
Console.log simple message | Code Architects

Table

The JavaScript console.table() method is a powerful tool for debugging and analyzing data. It allows you to log arrays or objects in a tabular format, making it easier to visualize and understand the data. The console.table prints the arrays/object in a tabular format. You can use the table to log iterable objects.

console.table({
    'firstName': 'John',
    'lastName': 'Doe'
});
Console table | Code Architects

In addition to logging data, console.table() also provides options for sorting and filtering the output. You can use the sort and filter options to control which rows are displayed in the table.

Error

The JavaScript console.error() method is used to log error messages to the console. It is similar to the console.log() method, but it also displays the message in a different color (usually red) to make it more noticeable. Use console.error to log errors in the console.

console.error("This is a error, Hehe...");
Javascript Console error message | Code Architects

Using console.error() can help you identify and debug issues in your code. For example, if you have a syntax error or a reference error, console.error() can help you quickly locate and fix the problem.

Warning

the console.warn logs the warning.

console.warn("Warning message");
JavaScript Console.log warning | Code Architects

Clear

the console.clear will clear the console panel of browser.

console.clear();
clearing the console.log panel | Code Architects

Group

In console panel, you can group multiple messages under a single name.

console.group("Group Title");
console.log("Message 1");
console.log("Message 2");
console.warn("Message 3");
console.groupEnd("Group Title");
image 8

Count

count a console message that is logged in the panel.

console.count("1");
console.count("1");
console.count("1");
console.count("1");
console.count("1");
image 9

Overall, console log is an essential tool for any JavaScript developer. It allows you to output messages and data to the console, providing a way to troubleshoot and debug your code. Whether you are just starting out with JavaScript or are an experienced developer, console log is a valuable tool to have in your arsenal.

Follow us on Instagram here. Read about the JavaScript blogs from here.

Thank you for reading the blogs, What do you think about the blog? let us know in the comment box.

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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

8 + two =