Datatype number with value one is the same as boolean true??
Hi all,
I Have a question regarding the datatypes. In my script I have a function that returns boolean true or a number. Like this:
//Returns a true or a number
var Return = function1()
//check return value
if(Return != true){
...
}
else{
...
}
So if the result value is true the else part is executed. When the return value is > 1 the if part is executed. So far so good. When the return value is 1 the else part is executed. I do not understand the problem. I also check the type of the retun value which is also a number when 1 is executed. Can anybody help me?
In JavaScript (and JScript) 1 is a truthy value, meaning it has a boolean value of true. That is, Boolean(1) == true. All numbers other than 0 are truthy, 0 is falsey.
http://james.padolsey.com/javascript/truthy-falsey/
http://www.sitepoint.com/javascript-truthy-falsy/
http://stackoverflow.com/questions/19839952/all-falsey-values-in-javascript