Let's talk about another type of scope, which is function scope.
So as usual, let's have some enough room here and let me comment this once and bring the comment down
here.
And this one is going to be as a function scope.
Come up here and save it.
Great.
So what is a function scope in JavaScript?
Function scope refers to the visibility of variables within a function.
If a variable is inside a code block, it means they are in a block scope.
For example, if statement and if a variable is inside, a function is being regarded as a function
scope.
So let's see.
So let's declare a function counts.
Let's say my function.
And then it go to error function this time around.
And for this function, let's declare a variable.
So let's say let x equal to.
Hello?
Great.
So let me call my function here as my function is that when I save it not in display because you are
not returning anything from this particular function.
But if I console dot log x let's see.
I see.
Hello, i have access to x because this variable is in the functions code because it has been declared
inside this function.
So I can access it inside.
But if I try to console.log the same x outside my function, let's see I get an error.
Meaning this function.
Sorry, this variable is not in the global scope but instead is in a function scope.
And again, even for this one, if I try to console log x before it's been declared.
Have a look.
You see, I get x six that cannot access x before initialization because I call the x before initializing
it.
That's what you call function scope.