Very strange line in some code, could someone help?

We can remove the useless parents and split the code into three lines:

return !foundMatch
    ? 0.0 
    : (Math.min(parseInt(100 * Math.max(nearest - 4.0) / -4.0, 0.0), 100)/100.0);

This is a ternary operator: condition ? if_true : if_false

So if it hasn't found a match, it returns 0, otherwise it returns the result of this expression:

Math.min(parseInt(100 * Math.max(nearest - 4.0) / -4.0, 0.0), 100)/100.0

Then it's just some math, with the radix being strange. According to mdn:

If radix is undefined or 0 (or absent), JavaScript assumes the following: If the input string begins with "0", radix is eight (octal) or 10 (decimal). Exactly which radix is chosen is implementation-dependent. ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. For this reason always specify a radix when using parseInt. If the input string begins with any other value, the radix is 10 (decimal).

So I'm not sure what the intention there would have been, but they probably just wanted to cast it as a decimal number.

/r/javascript Thread