Variable Scopes

Hello Friends,

During an exercise on scoops, something that was written next to it that contradicts what I learned.
For the avoidance of doubt, I’d like to ask you, to be sure.
Attaching a photo, with a red marking.

On the left, it is claimed that the same variable named “name” is the same variable used by the 2 functions that appear in the code section on the right, logEvent () and logTime ().

Correct me if I’m wrong but according to the code, those are two different variables, within scopes of different functions, and what they have in common is just their name (both are called ‘names’).

Thanks in advanced,
Idan.

Hi,
You’re correct. I don’t think it’s wrong, just the wording isn’t totally clear.
What I think it’s saying, is that in both functions there is a variable being set up exactly the same and used in the same way (not that the variables themselves are the same).
So, rather than repeating code it makes more sense to set it up once and then pass it in as a parameter (not to mention quicker and easier to change later, if need be)

Hope that helps

1 Like

Thanks buddy, and sorry for the late response.

Totally agree that the other way is the right one.
I guessed it was an inaccurate wording, but I felt I had to ask for reassurance so that there would be no doubts …

thank you again.

1 Like