Exercise – Scope
by manu troiani
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
*/
/**
* 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 */
jobteam = 'CCE';
var foo = function publishJobPositionDetails(){
var department = 'IT';
var jobPosition = 'Software Developer';
var output = "TEAM: " + jobteam + " , \nDEPARTMENT: " + department + ", \nPOSITION: " + jobPosition
//alert(output);
console.log(output);
function describeJobRequirements(){
var out2 = 'To work within the ' + jobteam + ' team \n we expect you to be a '+ jobPosition + '\n and we require Java and Javascript skills';
//alert(out2);
return out2;
}
var result = describeJobRequirements();
console.log(result);
}
//console.log( publishJobPositionDetails() );
//var job_desc = alert(publishJobPositionDetails());
foo();
/* 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
*/