enable console in LWC

How to use console.log and window.alert functions in Lightning Web Component

Lightning Web Component

Hey guys, today in this post we are going to see that how we can enable or how we can use JavaScript console and alert functions like console.log(), console.table(), console.error(),window.alert() etc. to debug our salesforce lightning web component [LWC] code.

Check also : How to Create Lightning Web Component And Deploy To The Salesforce Org

Problem : In lightning web components when you are trying to use javascript console.log() and window.alert() functions you will get following errors in your VS code ‘problems’ tab :

Unexpected console statement. eslint(no-console)[10,10]
Unexpected console statement. eslint(no-alert)[10,10]

Solution : To use console and alert function you need to add following statements in your JavaScript files :

LWC Example : 

Lightning Web Component : (myLWC.html)



LWC Output : 

fix error in lightning web component (LWC)

Related Resources :
Other popular Post :

Follow us on :




(Visited 4,492 times, 1 visits today)


Leave a Reply