DEV Community

Cover image for Print to console - console.log() and more
Tonmoy
Tonmoy

Posted on

Print to console - console.log() and more

Logging or printing messages to the console is a very basic way to diagnose and troubleshoot minor issues or bugs in your code.

In this article, I'll show you how to print to the console in JS, as well as all of the things you didn't know console could do.

  • To clear the console
    console.clear();
    Image description

  • Print string, number or boolean values in console
    console.log('Hi there');
    console.log(10);
    console.log(false);

    Image description

  • Print the value of a variable

let say = 'Hello';
console.log(say);
Enter fullscreen mode Exit fullscreen mode

Image description

  • Print an array to console
let quote = ['Keep','it','simple'];
console.log(quote);
Enter fullscreen mode Exit fullscreen mode

Image description

  • Print an object to console using log and table method
let person = {
  id:002,
  age:20,
  job:'tech'
}
console.log(person);
console.table(person);
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)