DEV Community

Think1s
Think1s

Posted on

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

Top comments (1)

Collapse
 
devsmitra profile image
Rahul Sharma • Edited

You can add syntax highlights as well.

Read here
github.com/adam-p/markdown-here/wi...