How to Clear the JavaScript Console in Google Chrome


In this article we are going to learn how to clear the JavaScript Console in Google Chrome. We have various methods to clear the console; but our question is why do we need to clear the console?

Sometimes we have lots of commands and logs printed in any browser console which makes it look substandard and packed with output. So, we need to clear the console. And there are multiple ways to clear the console of google chrome.

Using the console.clear() method

This method will clear the console and display the message on the console that the console was clear.

Example

Following is the example of the console.clear() method −

<!DOCTYPE html>
<html lang="en">
<body>
   <p>Please click the clear button to clear the console.</p>
   <button onclick="clearFunc()">clear</button>
   <script>
      function clearFunc() {
         console.clear();
      }
   </script>
</body>
</html>
  • We can also use the keyboard to clear the console. (Ctrl + L)

  • We can also use the clear log button on the top left corner of the chrome dev tools console to clear the console.

in the following screenshot, we have marked a circle on the clear log button.

  • On the macOS we can use (Command + k) for clear the log.

Updated on: 19-Dec-2022

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements