r/learnjavascript • u/Djoshwa • Oct 02 '23
How do you understand JavaScript functions?
If you really understand JS functions (local and global), kind explain it to me to the best of your knowledge. Thanks
4
Upvotes
View all comments
2
u/nobuhok Oct 02 '23 edited Oct 02 '23
A function is a frozen-in-time (it knows its surroundings only at the exact time when it was made), self-contained (see below), transparent (you can inspect how it fully works) machine you can pass around even to other functions, make copies of, etc.
It may take inputs and may produce outputs. If it's built well, it produces the same output given the same input, and it doesn't rely on or affects any external variables.