If the + value is set before any value without the previous value to +, the JavaScript engine will try to convert this variable to Number.If it is valid, it will give you an else number to which it will return NaN. for example
+ "1" // is equal to integer value 1 + "a1" // will be NaN because "a1" is not a valid number
In the case above
+"a1" != "a1" // true, so this is not a number, one case is satisfied +"1" == "1" // true, so it is number
Another simple case: why the expression below gives this conclusion
console.log("Why I am " + typeof + ""); // returns "Why I am number"
Because + "" is 0.
If you want to check if this is a number or not, you can use the following function
function isNumber(a){ return (+a == a); return (+(+a) >= 0);
Someone will correct me if I'm wrong somewhere.
Exception
source share