console methods in JavaScript

Today we’ll explain the various console methods in JavaScript and how to use it with examples.

console methods

  1. log()
  2. info()
  3. warn()
  4. error()
  5. clear()
  6. table()
  7. count()
  8. time() and timeEnd()
  9. group() and groupEnd()
  10. Custom console logs

1. log()

Use the log() method to print any type of the value. It could be a string, integer, object, array, boolean, etc.

console.log() - Clue Mediator
console.log() – Clue Mediator

2. info()

Use the info() method to display logs as information.

console.info() - Clue Mediator
console.info() – Clue Mediator

3. warn()

Use the warn() method to show the warning log in the console.

console.warn() - Clue Mediator
console.warn() – Clue Mediator

4. error()

Same as the above logs we can use the error() method to show the error log in the console.

console.error() - Clue Mediator
console.error() – Clue Mediator

5. clear()

Run the clear() command to clear the console log.

console.clear() - Clue Mediator
console.clear() – Clue Mediator

6. table()

The table() method allows us to generate a table inside a console. The input must be an array or an object which will be shown as a table.

console.table() - Clue Mediator
console.table() – Clue Mediator

7. count()

The console.count() method logs the number of times that this particular call to count() has been called.

console.count() - Clue Mediator
console.count() – Clue Mediator

8. time() and timeEnd()

Use the time() method to start a timer you can use to track how long an operation takes. The timeEnd() method stops a timer that was previously started by calling console.time().

console.time() and console.timeEnd() - Clue Mediator
console.time() and console.timeEnd() – Clue Mediator

9. group() and groupEnd()

Using the group(), your console logs are grouped together, while each grouping creates another level in the hierarchy.

console.group() and console.groupEnd() - Clue Mediator
console.group() and console.groupEnd() – Clue Mediator

10. Custom console logs

Use the style for custom console logs. We have to use the %c in the logs to add the style.

Custom console logs - Clue Mediator
Custom console logs – Clue Mediator

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

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