Skip to content

Debunking and using Console API within a browser and JavaScript

Ali Youssefi edited this page Apr 25, 2019 · 4 revisions

Summary

using the Console API provides debugging standardized abilities within the browser. Treated as a global object the console can be read from both inline JavaScript as well as libraries loaded (i.e. Dynamics 365 web resources). Common usage includes logging (informational and exceptions), profiling, timing, deserialization, etc.

Logging with the Console API

Logging can be achieved using multiple methods informing the browser of the severity level:

  • console.log
  • console.info
  • console.warn
  • console.error

A common example for output to the Console API is:

console.log('Hello World!');

Another example from the Mozilla Reference - Console Usage could be:

var someObject = { str: "Some text", id: 5 }; console.log(someObject);

and the output:

[09:27:13.475] ({str:"Some text", id:5})

Timing with the Console API

Using the console.time() method a developer can add instrumentation markers within code to determine duration of a particular action of interest. Consider the following usage:

function doSomething(){

console.time('doSomething()');

~ [code] ~

console.timeEnd('doSomething()');

}

Portal

Clone this wiki locally