Predict the output of the following javascript code

function randomOutput() {
  let x = 10;
  let y = 20;

  function innerFunction() {
    x = 30;
    let z = 40;
    console.log(`Inside innerFunction: x = ${x}, y = ${y}, z = ${z}`);
  }

  innerFunction();
  console.log(`Outside innerFunction: x = ${x}, y = ${y}`);
}

randomOutput();

 

 

 

 

  • Inside randomOutput:

    • x and y are defined with values 10 and 20 respectively.

    • innerFunction modifies x to 30 and logs x = 30, y = 20, and z = 40.

    • After calling innerFunction, it logs x = 30 and y = 20.

So the output will be:

Inside innerFunction: x = 30, y = 20, z = 40

Outside innerFunction: x = 30, y = 20