What is Console Log?

15/01/2022
Console Log

Console.log() is used to print messages to the console of web browsers. It is generally used when testing whether a function is working on the Javascript side.

console.log();

When the operation is performed in conditional structures such as if else, switch case or for loops in Javascript codes on the pages, it can be tested whether the function works by printing a message to the console of the browser with the help of console.log.

For example, when the code below runs in a web browser, it prints an OK message to the browser’s console.

<button id="btn">Button</button>

<script>
    document.getElementById('btn').onclick = function () {
       console.log('OK');
    };
</script>

Google Chrome Console:

Console Log