1

A question about scope which I couldn't find online.
If you would have a piece of code like:

Function foo(myVar) {
return myVar + 1
}

Would myVar be bounded to the scope of foo?
Thank you for your time.

Edit: this is different from a question about scopes of variables in arguments because I wasn't sure if that would apply to arguments, since they weren't stated with var before them.

Steen
  • 6,573
  • 3
  • 39
  • 56
blipman17
  • 523
  • 3
  • 23
  • @VisioN I'm sure this is a duplicate, but that linked question doesn't have much to say about the distinctions between function parameters and local variables. – Pointy Jun 25 '14 at 14:29
  • 1
    function parameters are *essentially* the same as local variables as far as scope goes. Not exactly the same, but mostly you can think about them as equivalent. – Pointy Jun 25 '14 at 14:30
  • Where? I couldn't find it. I will look again though – blipman17 Jun 25 '14 at 14:31
  • @Pointy The linked question provides the central idea: there are a global scope and a local scope. Everything that is defined within a function, including functional arguments, is defined in the local scope of this function. There is no detailed explanation of the difference between parameters and local variables, but scope-wise they behave the same. – VisioN Jun 25 '14 at 14:38
  • @VisioN oh I agree; I just was noting that mention of the similarity between parameters and locals is either not mentioned, or buried somewhere in the rest of the information there. The comment I added above should help this OP I hope :) – Pointy Jun 25 '14 at 14:47
  • @Pointy Yup! That's why I have upvoted it ;) – VisioN Jun 25 '14 at 14:49
  • It helped me a lot. thank you Pointy Yup! and VisioN – blipman17 Jun 26 '14 at 13:17

0 Answers0