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)

myLWC.js

myLWC.js-meta.xml

LWC Output : 

fix error in lightning web component (LWC)

Related Resources :
Other popular Post :

Follow us on :

Facebookhttps://www.facebook.com/sfdcmonkey/

Instagramhttps://www.instagram.com/sfdc_monkey/

 

(Visited 949 times, 1 visits today)

2 comments

Leave a Reply