How to Clear Console Using JavaScript

Shraddha Paghdar Feb 15, 2024
  1. What Is Console in JavaScript
  2. Use the console.clear() Method to Clear a Console in JavaScript
How to Clear Console Using JavaScript

A web console is mainly used to record information associated with a web page, such as network requests, JavaScript, security errors, warnings, CSS, etc.

It allows us to interact with a web page by executing a JavaScript expression within the page content.

What Is Console in JavaScript

In JavaScript, a console is an associate object that gives access to the browser’s debugging console.

We can open a console in the web browser:

  • For Windows Use Ctrl+Shift+I.
  • For Mac Use Command+Option+K.

The console object provides us with several methods, such as:

  • clear()
  • warn()
  • group() and groupEnd()
  • time() and timeEnd()
  • table()
  • error()
  • custom console logs
  • log()
  • count()

Use the console.clear() Method to Clear a Console in JavaScript

The console object provides access to the browser debug console, i.e., the web console in Firefox.

It is accessible from any global.window object for navigation purposes as specific variants in workers via the real estate console.

It is exposed as Window.console and can be referenced as a console.

console.log('Hello World!')

The console will be deleted. In the case of Chrome, it will print a simple overlay text like: The console has been deleted, whereas in Firefox, no message is returned.

console.clear()

Output:

clear console using JavaScript

Shraddha Paghdar avatar Shraddha Paghdar avatar

Shraddha is a JavaScript nerd that utilises it for everything from experimenting to assisting individuals and businesses with day-to-day operations and business growth. She is a writer, chef, and computer programmer. As a senior MEAN/MERN stack developer and project manager with more than 4 years of experience in this sector, she now handles multiple projects. She has been producing technical writing for at least a year and a half. She enjoys coming up with fresh, innovative ideas.

LinkedIn