What are Scoping Rules? Why are they so Important in all Programming Languages?
https://www.computersprofessor.com/2016/06/what-are-scoping-rules-why-are-they-so.html
Scoping is an important concept in
programming.
Scope determines how a variable can be accessed.
In java script variables can be either
local (or) global.
Global:-
Global scoping means
that a variable is available to all parts of the program. Such variables are
declared outside of any function and are usually used to hold static data, that
you won’t alter once it has been declared.
Local:-
Local variables are
declared inside a function. They can only be used by that function. If you want
the value associated with a local variable to be available to other functions.You must pass it as parameter.
<html>
<head>
<title> global & local </title>
<script language = “ java script”>
var
a = 32;
var
temp = a;
var
b = set – local (17);
document
.write (“The global is “ + a);
document.
write (“ b is “ + b);
function
set_ local (num)
{
var
a = num;
alert
= (“temp is “ + temp);
return(a);
}
</script>
</head>
<body>- - - -</body>
</html>