r/programming • u/fagnerbrack • Sep 19 '16
Is your JavaScript function actually pure? Or does this function behaves like a Mathematical Function in all the situations I will encounter in my code?
http://staltz.com/is-your-javascript-function-actually-pure.html
0
Upvotes
1
4
u/jms_nh Sep 19 '16
OP is wrong; a mathematically pure function acts upon plain values identically. By screwing around with valueOf in Javascript, you are creating 'impure' behavior but that's the fault of the argument to the function, not the function itself.
12
u/Baaz Sep 19 '16
This is nonsense. The examples don't break the prerequisite of pureness:
Who cares if the output is null or undefined or NaN? Same input, same output, by your own definition. So this doesn't break it at all.
Also, the example of assigning random values to a parameter is BS, because now you're changing the input. Different input, different output, still doesn't break the rule for pureness.