In this section, we will learn what the console clear() method is and how to use it in JavaScript.
JavaScript Console clear() Method
The `clear()` method is used to clear all the logs that already pasted on a browser console.
After clearing the logs, this method will print the message `Console was cleared` on the console as well.
Console clear() Method Syntax:
console.clear()
Console clear() Method Parameter:
The method does not take an argument.
Console clear() Method Return Value:
The return value of this method is undefined.
Example: using Console clear() method in JavaScript
console.log("Hello");
console.log("My name is: ");
console.log("John Doe");
setTimeout(()=>{
console.clear();
},3000);
After 3 seconds, the console’s logs will be cleared.