PDA

View Full Version : Local and Global Scope Variables in JavaScript



charlesprabhu
07-20-2021, 06:00 AM
Global Variables − A global variable has a global scope which means it can be defined anywhere in your JavaScript code.
Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.

yuva12
07-21-2021, 10:57 AM
JavaScript has global scope and local scope. Variables declared and initialized outside any function become global variables. Variables declared and initialized inside function becomes local variables to that function. Variables declared without var keyword inside any function becomes global variables automatically.