JS Interview Question #2 (Accidental Global Variable)

learndaily1

Think1s

Posted on March 22, 2022

JS Interview Question #2 (Accidental Global Variable)

Visit think1s to get more such questions.

Revise Accidental Global Variable concepts to answer this questions.

What is the output the following code?

function getNumber() {
        var a = b = 2;
        a++;
        return a;
      }
      console.log(typeof a);
      console.log(typeof b);

Enter fullscreen mode Exit fullscreen mode

To know the answer click here

What is the output the following code?

 function getNumber() {
        var a = b = 2;
        a++;
        return a;
      }
      getNumber();
      console.log(typeof a);
      console.log(typeof b);

Enter fullscreen mode Exit fullscreen mode

To know the answer click here

💖 💪 🙅 🚩
learndaily1
Think1s

Posted on March 22, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related