Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

differentiate between 0 & ""

I know, I know there must be some threads covering this topic. But I used the search and didn't get the answer which fits my needs. So here we go:

i want to check one "if" condition , in that if variable is having values like "null" or "undefined" or "" or '' then i want to assign variable value as "N/A" & if value is zero (0) it should not assign "N/A" to that variable.

But the problem is here that "" or null == 0 is true,

So please help me to get out this problem, Thanks in Advance

like image 988
Mahesh Kalyankar Avatar asked Jul 30 '15 15:07

Mahesh Kalyankar


1 Answers

Use === for comparisons in JavaScript,

// type doesn't match gives false
0 === null; // false
0 === undefined; // false
0 === ''; // false
0 === false; // false
0 === "0"; // false

// type matches
0 === 0; // true
like image 142
Paul S. Avatar answered Sep 30 '22 15:09

Paul S.