Krzysztof Czernek
1 min readOct 22, 2018

--

Cosmin Mavrichi

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:

  1. We call the uppercaseName function twice, with the same argument — and yet we get different results,
  2. 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!

--

--

Krzysztof Czernek
Krzysztof Czernek

Written by Krzysztof Czernek

Tech Lead, Full Stack Developer, Consultant

Responses (1)