this post was submitted on 06 Nov 2023
1 points (100.0% liked)

Programmer Humor

42274 readers
11 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] yogthos@lemmy.ml 1 points 2 years ago

Side effects are when your function has a reference to some state outside its scope and modifies that state. A function that produces different outputs when it's called, such as getting a current time is not an example of a side effect. Again, the issue here is that Js tries to infer what to do with a bad input, a number outside acceptable range, instead of simply rejecting it.

My point isn't that you can't write a better function that's less error prone, but the fact that Js allows such things to happen in the first place. It's a very easily avoidable problem at the API level.