Mahdi_Nine Mahdi_Nine - 2 years ago 112
Javascript Question

How do I check for null values in JavaScript?

How can I check for null values in JavaScript? I wrote the code below but it didn't work.

if (pass == null || cpass == null || email == null || cemail == null || user == null) {

alert("fill all columns");
return false;


And how can I find errors in my JavaScript programs?

Answer Source

Javascript is very flexible with regards to checking for "null" values. I'm guessing you're actually looking for empty strings, in which case this simpler code will work:

if(!pass || !cpass || !email || !cemail || !user){

Which will check for empty strings (""), null, undefined, false and the numbers 0 and NaN

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download