Global and Local Variable tutorial in JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Global Local Variable JavaScript</title>
<script>
// Here below "a" is Global Variable, Global Variable will work for both inside function and outside function
var a = "Hello World<br><br>";
function hello() {
// Here below "b" is Local Variable, Local Variable will work for only inside function (Not outside function)
var b = "How are you ?<br><br>";
document.write(a);
document.write(b);
}
hello();
document.write(a);
document.write(b);
</script>
</head>
<body>
</body>
.png)
.png)
Comments
Post a Comment