Basic JavaScript: Global Scope and Functions

Hello, something I found while working on this section. In that it states" You should always declare your variables with var". However, I’ve found that this is not necessarily the case when declaring the variable as a parameter. If I try to use it there I get a “property declaration expected” error. e.g

\*THIS IS GOOD*/
function myFunction(greeting) {
  console.log(greeting);
}

myFunction("Hello World");
\*THIS IS BAD*/
function myFunction(var greeting) {  
  console.log(greeting);
}

myFunction("Hello World");

Is this intended? As in a way for us to kinda come to conclusion on our own or?

Function parameter and variable are two different things.

Yes I can see that now. I had a different train of thought when staring at it. But once I spent some time thinking about it after I think I can see why it is the way it is.

thanks for replying.

Np. It will take some time to fully grasp some of those concepts, but don’t worry, we all have gone through that. :man_teacher: :slightly_smiling_face: