JavaScript console clear() Method

JavaScript console.clear() Method is “used to clear the console if the console allows it”. The clear() method also writes “Console was cleared” in the console.

Syntax

console.clear()

Parameters

None.

Return Value

None.

Example: How to Use console.clear() Method

<script>
  function clearFunc() {
    console.clear();
  }
 
  clearFunc();
</script>

Output

How to Use console.clear() Method

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.

We can use (Command + k) on the macOS to clear the log.

Browser compatibility

The console.clear() method is supported in all browsers.

Leave a Comment