I would recommend explicit condition checks. When using:
if (area.regionCode) { }
Style of logic, one is treating varAny as a boolean value. Therefore, JavaScript will perform an implicit conversion to a boolean value of whatever object type varAny is.
or
if(Boolean(area.regionCode)){
codes here;
}
both will work same
returns false for the following,
- null
- undefined
- 0
- ""
- false.
beware returns true for string zero "0" and whitespace " ".
you can also first trim the output so " "
issue will be solve
here tutorial How do I trim a string in javascript?
in the @mttrb and @nnnnnn described case you can first convert string to either int or float by parseInt()
and parseFloat()
check this Converting strings to numbers