Exercise – Scope

by Diarmuid Dunne

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 globalVariable = 10;

function functionOne()
{
    globalVariable += globalVariable;
    console.log("Global " + globalVariable);
    var localVariable = 10;
    console.log("Local " + localVariable);
     
    function functionTwo()
	{
        console.log("Local " + localVariable);  
    }
}