1 min readOct 22, 2018
Excellent question, let me clarify!
The difference is that the uppercaseName
function depends on the variable that is defined someplace else (firstName
). The firstName
variable could (later on) be reassigned to a different value, thus changing the behavior of uppercaseName
.
To see why it’s suboptimal, consider this example:
This showcases two problematic things about uppercaseName
:
- We call the
uppercaseName
function twice, with the same argument — and yet we get different results, - To figure out what is going to be printed in line #13, you need to analyze a lot of code and see what the value of
firstName
is right now.
You can hopefully see why none of this could have happened with the calculatePrice
function.
Let me know if this makes sense!