Search notes:

Browser Object Model: console.log()

console.log(…) allows to write messages into the debugging console. Thus, it is a handy and cheap way to write debug messages.
If the message text is prefixed with %c, the second parameter of console.log can be given a set of CSS formatting rules that change the appearance of the written log messages.
With %s, %d and %f`, there is a rudimentary printf functionality.
In the following example, the content of an object (obj) is expanded using the JSON.stringify method.
<html>
<head>
  <meta charset="utf8">

<title>console.log</title>

<script type="text/JavaScript">

  function main() {
  
    console.log('');
    console.log('foo bar');
  
    obj = {x: 'eggs', y: 'why'};
    console.log(JSON.stringify(obj));
  
    console.log(
      '%cBIG and red',
      'color: #ff0000; font-size: 40px;'
    );
  
    console.log(
      '%cbold and blue',
      'color: #0000ff; font-weight: bold'
    );
  }

</script>
</head>
<body onload='main()'>

</body>
</html>
Github repository Browser-Object-Model, path: /console/log.html
This HTML document writes:

See also

In Firefox, the Web Console can be opened with ctrl+shift+K.
The console object of the browser object model

Index