Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome DevTools: what's this arrow(<-) meaning?

I am confuse about this symbol (<-) in Chrome DevTools

javascript while loop in DevTools Console

It's return value or console value?

When I run this while loop

var i = 0;
while (i < 5) {
    console.log(i);
    i++;
}

the console log spits out 4 twice, the last 4 have a (<-) in a front, what's meaning?

like image 414
Phonbopit Avatar asked Feb 17 '14 04:02

Phonbopit


People also ask

What does purple mean in DevTools?

It is white space. For example you have a container with 100% of width and two divs inside, one of those with 50% and another width 40% of width, it means that there is 10% of space empty... this 10% would be shown in this purple dashed line area by the Google inspector.


1 Answers

This has to do with the nature of the eval function. Note that:

var i = 0, j = while(i < 5) { i++; };

Produces a compile error. However,

var i = 0, j = eval('while(i < 5) { i++; }');

Assigns the value 4 to j. Why is this? Quoting from MDN:

eval() returns the value of the last expression evaluated.

So in short, it evaluates all the calls to console.log in your expression, then also logs the return value from the eval-ed expression itself, which just happens to be the result of the last i++.

like image 166
p.s.w.g Avatar answered Oct 08 '22 17:10

p.s.w.g