getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.
Other
179.29k stars 33.48k forks source link

Get Started - Chapter 2 - Declaring and Using Variables - Example #1733

Closed samcareelmont closed 3 years ago

samcareelmont commented 3 years ago

I already searched for this issue

Edition: 2nd

Book Title: Get Started

Chapter: Chapter 2: Surveying JS

Section Title: Declaring and Using Variables

Question:

Besides var / let / const, there are other syntactic forms that declare identifiers (variables) in various scopes. For example:

function hello(myName) {
    console.log(`Hello, ${ myName }.`);
}

hello("Kyle");
// Hello, Kyle.

The identifier hello is created in the outer scope, and it's also automatically associated so that it references the function. But the named parameter myName is created only inside the function, and thus is only accessible inside that function's scope. hello and myName generally behave as var-declared.

It seems to me that myName behaves more like a let-declared variable than like a var-declared variable.

getify commented 3 years ago

why?

samcareelmont commented 3 years ago

I've read the section a few times more and the question has disappeared. Sorry for the bother and thanks for writing this book!

(I got myself confused because a function looks like a block since it's also defined using curly brackets.)