Hii~!
I was trying this codewars challenge…
here is my solution
switch (n) {
case (n == Number.MAX_VALUE): return "Input number is Number.MAX_VALUE";
case (n == Number.POSITIVE_INFINITY): return "Input number is Number.POSITIVE_INFINITY";
case (n == Number.MIN_VALUE): return "Input number is Number.MIN_VALUE";
case (n == Number.NEGATIVE_INFINITY): return "Input number is Number.NEGATIVE_INFINITY";
case (isNaN(n)): return "Input number is Number.NaN";
default: return "Input number is " + n;
}
}
console.log(whatIsIt(1.7976931348623157e+308));
//gives me the same number 1.7976931348623157e+308 rather than giving me Number.MAX_VALUE
when i looked in to codewars solution they have used true in the switch case condition
switch(true) {
}
i want to know what’s happening here when the condition is true in switch case and what’s wrong with n as my condition
Please explain me
Thanks!