Exercise – Scope

by Andrew Corliss

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 myGlobal = 25;

function myFunc() {
	console.log('The Var "myGlobal" is %d', myGlobal);
};

function shareEven() {
	console.log('The Var "myGlobal" is %d', myGlobal);
};


function setChild() {
	var b = 12;
    console.log('My var b is %d', b);
    function childOMine() {
        console.log('My var b is %d', b);
    };
    childOMine();
};
myFunc();
shareEven();

setChild();