Expand Minimize

Consider to not use, or shim the console object

The console object is only available in IE, after the developer console has been opened once, therefore throwing an error

CheckId SPC018902
TypeName NoDeveloperConsoleUsage
Severity Warning
Type JavaScriptFile

A shim is code that intercepts existing API calls and implements different behavior. The idea here is to normalize certain APIs across different environments. So, if two browsers implement the same API differently, you could intercept the API calls in one of those browsers and make its behavior align with the other browser. Or, if a browser has a bug in one of its APIs, you could again intercept calls to that API, and then circumvent the bug.
Bad Practice

// Browser console
console.log('Hello world!');console.error('Something bad happened.');

Good Practice
// custom shimed console
Console.log('Hello world!');

Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.