Christian Cisneros
Christian Cisneros

Reputation: 18

Why only the return value of the second function call is printed?

When I write this code in the console:

function lol() {
    var a = 6;
    return a;
}

function test() {
    var a = 8;
    return a;
}

lol();
test();

It prints only the return value of the second function call like this:

8

Why this is happening? Can anyone explain me what happens under the hood?

Upvotes: 0

Views: 90

Answers (1)

Pointy
Pointy

Reputation: 414096

The console only prints the value of the last statement evaluated. That's just what it does. If you want more, you can explicitly call console.log( lol() ); or whatever.

Upvotes: 2

Related Questions