What is the use of console.log?
Please explain how to use it in JavaScript, with a code example.
Quoting MDN Docs here
console— contains many methods that you can call to perform rudimentary debugging tasks, generally focused around logging various values to the browser's Web Console.By far the most commonly-used method is
console.log, which is used to log the current value contained inside a specific variable.
let myString = 'Hello World';
console.log(myString);
Also remember console is a part of global window object in the web browser. Thus the following is also technically correct but isn't used in practical scenario.
let myString = 'Hello World';
window.console.log(myString);