Declare a function, such as declaring a variable.
As the code shows, after running the function define (), the variable A is declared as a global variable. You can refer to variable A in the Hello () function.
More specific examples
Take a look at the following code:?
As you can see, after the function fun1 is called, the value of str1 is changed within the function.
Then make a slight change to the above code:?
See no, the value of str1 is not changed by the function fun1.
Obviously, the VAR keyword affects the scope of the variable.
Outside the function: variables are global variables, whether or not they are declared with Var.
Inside the function: If the variable does not use the var keyword declaration, then it is a global variable, only with the Var keyword declared, is the local variable.
To avoid potential risks, be sure to use the VAR keyword to declare variables.