Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

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

Raghav Sharma24
Giga 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.

View solution in original post

2 REPLIES 2

Raghav Sharma24
Giga 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.

Not applicable

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

//your code

}

 

 

Please mark as correct answer if this solves your issue.