What is the use of console.log
?
Please explain how to use it in JavaScript, with a code example.
In early days JS debugging was performed through alert()
function - now it is an obsolete practice.
The console.log()
is a function that writes a message to log on the debugging console, such as Webkit or Firebug. In a browser you will not see anything on the screen. It logs a message to a debugging console. It is only available in Firefox with Firebug and in Webkit based browsers (Chrome and Safari). It does not work well in all IE releases.
The console object is an extension to the DOM.
The console.log()
should be used in code only during development and debugging.
It’s considered bad practice that someone leaves console.log()
in the javascript file on the production server.