getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.
Other
178.28k stars 33.42k forks source link

Scope and Closures: Counting the parameter of Console.log() as a target variable. #1692

Closed algotrex closed 3 years ago

algotrex commented 3 years ago

Please type "I already searched for this issue": I already searched for this issue

Edition: (1st or 2nd) 2nd

Book Title: Scope & Closures

Chapter: 1

Section Title: What's the Scope?

Question: In the section "Compiler Speak" where you enumerate all the source and target variables, you mention there are 5 target variables, I am wondering why we don't count the first argument of the console.log() function in the last line of the code: console.log(nextStudent); As I understand the function log() takes an obj1 parameter (see MDN documentation), so why don't we count this as a target variable for the same reason we count the studentID parameter as a target variable when getStudentName is invoked?

getify commented 3 years ago

The nextStudent there is an argument, not a parameter. The difference is in what's passed in at the call-site vs what's received in the function signature. An argument is a value or source-reference variable, whereas a parameter is a target-reference. If we were showing the implementation (internally in the engine) of the log(..) function, we'd potentially list out a parameter name for that first parameter, and that would be a target-reference.

algotrex commented 3 years ago

Thanks for the feedback!