The CreatorCon Call for Content is officially open! Get started here.

How to validate empty in if condition

SK36
Tera Contributor

Hi all,

In catalog client script, when value is empty or null, how to deal in if condition?

eg:

Var val;                             //or val='' whatever. But it is empty

if(val != null || val !=''){    //its not working.

alert(val);

}

So, how to deal empty variable?

1 ACCEPTED SOLUTION

RaghavSh
Kilo Patron

when you have two "NOT" conditions always use && between them instead of ||.

Try below:

Var val;                             

if(val !='' && val !=null){    

alert(val);

}


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

View solution in original post

2 REPLIES 2

RaghavSh
Kilo Patron

when you have two "NOT" conditions always use && between them instead of ||.

Try below:

Var val;                             

if(val !='' && val !=null){    

alert(val);

}


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

Community Alums
Not applicable

Try below if condition if var is empty
if(!var){

//your code

}

 

 

Please mark as correct answer if this solves your issue.