JavaScript function parameters

Hi guys my first question on here, but here goes…

Might seem like a really dumb question because I’m new to programming.
I’ve just got onto to the lesson on functions on the JavaScript course. My question is when you pass parameters through the function that you are creating does it matter if the parameter is a pre-defined variable outside of the function? Additionally, does it matter what kind of variable it is (const, var, let) or only certain variable types can pass through the function?

Once again sorry for the ■■■■■■■■ question, but an answer could really clear things up for me. Thanks!

Variables are names that refer to values, and it’s the value you’d send in when calling a function, not the name.

2 Likes

I am aware that when calling a function after it has been created the parameters can only be values, but is this the same case for when the function is being created?

I feel like I’m missing something…

The variables in the parameter list exist in the function’s own scope.

A function can see variables that are in its surrounding scopes, but you’ll find the innermost variable of that name first, and you’ll stop searching there when resolving the name.

let a = 1
let b = 1
{ // new scope
  let a = 1
  a += 1 // first a found is the one in this scope
  b += 1 // first b found is the one just outside this scope
  console.log(a, b) // 2 2
}
console.log(a, b) // 1 2
1 Like

And var/let/(nothing) affects how far “out” the variable gets created. var is function-local, let/const is scope-local, if you omit it then it’s global

1 Like

Thanks, that cleared things up.

1 Like