When programming and HP you'll often work with functions a function is a block of statements that can
be used repeatedly in a program functions can be used to perform many different types of actions and
HP has thousands of them built in we'll be exploring functions later in this course.
For now it's just important to know how to work with variables inside and outside of function a variable
that is declared outside of function is known as a global scope variable.
It can only be accessed outside of function in this example.
We declared the variable x with a value of five outside the function test one.
This means that it's a global variable.
The purpose of this function is to output the value of X and we have an equal statement here to do that
since X has been declared outside the function the output will not work.
It will produce an error is shown here in our web browser
we can see that the error says undefined variable X so it does not recognize the variable
Now in contrast to a global scope variable.
We also have local scope variables a local scope variable can only be accessed inside a function in
this example.
We have a function named test to
inside this function.
We've declared variable Y and assign a value of 5
if we try to output the value of y inside the function then we can see in our browser that it does work
so on the right side we can see this statement here.
Value of y is 5 and that corresponds to where echo statement where we're trying to output the value
of y since Y is declared inside the function it works.
This is a local scope variable but if we try to access the local scope variable outside of the function.
So here we have a separate echo statement where we're trying to output the value of y again but this
time outside the function while this is going to result in an error and you can see on the right hand
side here that it does not output the actual value of y.
It gives us an undefined variable error so that's the difference between global scope and local scope
variables.