Exercise – Scope
by Shane Porter
JavaScript
/**
* Exercise:
*
* Function Scope
*
* Work in the console, or use "console.log()" to output to the console
* from the script
*
* Write two functions that share the same, global variable
* - Verify this by logging the value of the variable to the console
* from within each function
* Write two functions that share a non-global variable
* - Verify this by logging the value of the variable to the console
* from within each function
*/
/*
var a = "Beer";
function fn1() {
return a;}
function fn2() {
return a;}
console.log(fn1() === fn2());
*/
function fn3() {
var globalinner = "fn3"
//console.log(globalinner);
function fn4() {
globalinner ="fn4"
return globalinner;
}
console.log(fn4());
return globalinner;
}
console.log(fn3());