4

I have been using !$A.util.isEmpty(var) to check if value in empty/null/undefined in aura but this is not supported in LWC. What will be equivalent of this expression in LWC.

I don't want to write like if(this.var!==null && this.var!==undefined && this.var!=='')

7

This is a great question. Actually, it's more of a Javascript question than a LWC related question.

Quite simply because the answer is not related to LWC but to pure Javascript.

You just need to use the below code:

if(var){
}

In fact, Javascript will check if the var value is not undefined, not null and not an empty string.

EDIT

If we had to compare Aura to LWC in general, I would say that LWC is a real Javascript framework, a modern framework. This often involves Javascript takes a much more important place than the view, unlike Aura. But also that it is possible to use all the power of today's Javascript. And this is awesome!

  • Thanks @Martin! This is simple and elegant. – devforce Oct 30 '19 at 13:36
  • Glad I could help @devforce ! – Martin Lezer Oct 30 '19 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.