Define the following functions in the console ornode -i : function junk1() { for(i1=1; i1
Question:
Define the following functions in the console ornode -i :
function junk1() {
for(i1=1; i1<=2; i1++){console.log(i1);}
return `i1 is ${i1}`;
}
function junk2() {
for(var i2=1; i2<=2; i2++){console.log(i2);}
return `i2 is ${i2}`;
}
function junk3() {
for(let i3=1; i3<=2; i3++){console.log(i3);}
return `i3 is ${i3}`;
}
a. Executejunk1() theni1 explain whyi1 is defined outside the function.
varretString =junk1();
console.log("Junk1=" +retString);
console.log("i1=" +i1);
b. Executejunk2() theni2 explain why you getUncaught ReferenceError: i2 is not defined when you try to usei2 outside the function.
c. Executejunk3() theni3 explain why you getUncaught ReferenceError: i3 is not defined for each of these and why the return valuei3 is 3 does not appear as it does for the previous examples (that is, you cannot usei3 outside the function or outside the for-loop).