Debugging in lightning using Javascript Console API.

Updated: Jan 17, 2020

Putting debug statement in code is an essential part of finding bugs and making sure that code is working as expected. Anyone who worked in Aura Component has used the console.log() method to log on the console screen but very few salesforce developer knows that console API provides wide range of methods which can also be used in debugging efficiently.


This blog will discuss each method with some example.


1. assert() - assert needs no introduction. It accepts two arguments and if the first argument is false, it will display the message you put as the second argument.

Ex -

let flag = false;

console.assert(flag, "Something is wrong");


in this example, "Something is wrong" will be displayed on the console screen.


2. clear() - Clears the console screen.

Ex -

console.clear();


3. error() - Logs error on the screen. It shows the message in the form of error.

Ex -

console.error("Something wrong has happened");