A side effect is what happens when a function shows a dialog box or writes text on the screen of your computer.
By definition, a side effect is something that changes the way a machine works and potentially affects what comes after it.
On the other hand, a function can also produce values that don’t necessarily mean it’s a side effect because it’s used for something else.
What’s a function without a side effect? (Example)
The function Math.max takes any number of arguments and returns the biggest number.
let bigNumber = Math.max(2,234,345,3,24); return bigNumber;
When a function produces a value, it’s said to return that value.
Function calls can be used within expressions
Here’s an example of a function call that’s being used inside of an expression.
console.log(Math.min(2,234,345,3,24) + 20); // -> 22
Math.min does the opposite of what Math.max does and it outputs the smallest number in the set.
You see here that once it’s selected the smallest number (2), it then proceeds to add that value to 20 which is the outer expression.