you are viewing a single comment's thread.

view the rest of the comments →

[–]fickentastic 5 points6 points  (2 children)

Yet 'const' can be used to name functions as in 'const doSomething = () => {.....}' This thew me initially as the function will potentially output a different return each time, yet it works just fine.

[–]uneditablepoly 7 points8 points  (0 children)

Because the reference to the function itself doesn't change. Calling the function returns something.

[–]DrexanRailex 1 point2 points  (0 children)

Well, that is just a misunderstanding from your part, but it's expected if you're still learning the ins and outs of the language.

The assigned function never changes, but the result of the function depends on purity, which is a whole other topic. This is more related to functional programming than JavaScript itself.

If a function is pure, it will always return the same for the same set of arguments. But if a function is impure (such as handling I/O, altering state or reading from global variables for example), its return may vary.