5. Write a JavaScript script that has subprograms nested three deep and in which each nested subprogram references variables defined in all of its enclosing subprograms.
please attached an output!!!!!
functionParentFunction()
{
varparentX = 5;
console.log(parentX);
functionsubChild1() {
varsubChild1Y = parentX + 15;
console.log(subChild1Y);
functionsubChild2() {
varsubChild2Z = (subChild1Y + parentX) * 2;
console.log(subChild2Z);
functionfinalSubChild() {
varfinal = parentX + subChild1Y + subChild2Z;
console.log(final);
alert('Alert From Deepest Nested Function\nParentX = '+ parentX +'\nsubChildY = '+ subChild1Y +'\nsubChildZ = '+ subChild2Z +'\nadded together = '+final);
}
finalSubChild();
}
subChild2();
subChild1();
}
ParentFunction();
Get Answers For Free
Most questions answered within 1 hours.