Is this an example of variable shadowing in JavaScript?

fakeguybrushthreepwood picture fakeguybrushthreepwood · Aug 10, 2012 · Viewed 37.9k times · Source

I learnt about the term variable shadowing in Eloquent Javascript (Chapter 3), but I am trying to understand a precise, basic example of the concept.

Is this an example of shadowing?

Answer

Madara's Ghost picture Madara's Ghost · Aug 10, 2012

That is also what is known as variable scope.

A variable only exists within its containing function/method/class, and those will override any variables which belong to a wider scope.

That's why in your example, a euro sign will be shown, and not a dollar. (Because the currencySymbol containing the dollar is at a wider (global) scope than the currencySymbol containing the euro sign).

As for your specific question: Yes, that is a good example of variable shadowing.