I am looking for some guidance on the difference between a global scope variable and a local scope variable. Thanks.
相关问题
- JavaScript variable scope question: to var, or not
- how to Enumerate local fonts in silverlight 4
- Store data and global variables using the Applicat
- Scope on each last elements of a has_many relation
- Is there any point in using local functions if to
相关文章
- Rails scope for values only between two dates
- How to scope closure's variables in CF10?
- javascript setInterval() and Variable Scope
- Cannot access self:: when no class scope is active
- Function hiding and using-declaration in C++
- Is there a way to call a private Class method from
- Nodejs accessing nested variable in global scope
- JS loop variable scope
Global variable - declared at the start of the program, their global scope means they can be used in any procedure or subroutine in the program.
Local variable - declared within subroutines or programming blocks, their local scope means they can only be used within the subroutine or program block they were declared in.
Resource: Fundamentals of Programming: Global and Local Variables
Resource: Difference Between Local and Global Variables
The difference is where the variable can be accessed or modified. (in the contents of a class for example) A global variable can be accessed or modified anywhere within the class. A local variable, if created in a function within the class, can only be used within that function.
This site provides a nice explanation: https://en.wikibooks.org/wiki/A-level_Computing/AQA/Problem_Solving,_Programming,_Data_Representation_and_Practical_Exercise/Fundamentals_of_Programming/Global_and_Local_Variables
Example from the link above:
Output would be: 123 234 123
Global scope variables can use within the program anyware. Global variables are declaring outside any functions. Local scope variable value is only for that particular scope (function).Local variables are declaring inside that particular function.
Here you cannot print the value of sVariable outside the function as it is a local variable. But you can print the value of fVariable outside and inside both of the function as it is a global variable