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
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.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.