-
Notifications
You must be signed in to change notification settings - Fork 3
Debunking and using Console API within a browser and JavaScript
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 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})
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