Chrome DevTools:此箭头(< ;-)是什么意思? [英] Chrome DevTools: what's this arrow(<-) meaning?
问题描述
我对Chrome DevTools中的这个符号(< ;-)感到困惑
I am confuse about this symbol (<-) in Chrome DevTools
它是返回值还是控制台值?
It's return value or console value?
当我在while循环中运行
When I run this while loop
var i = 0;
while (i < 5) {
console.log(i);
i++;
}
控制台日志吐出4次两次,最后4次在前面有(< ;-),这是什么意思?
the console log spits out 4 twice, the last 4 have a (<-) in a front, what's meaning?
推荐答案
这与eval
函数的性质有关.请注意:
This has to do with the nature of the eval
function. Note that:
var i = 0, j = while(i < 5) { i++; };
产生编译错误.但是,
var i = 0, j = eval('while(i < 5) { i++; }');
将值4
分配给j
.为什么是这样?引用自 MDN :
Assigns the value 4
to j
. Why is this? Quoting from MDN:
eval()
返回最后一个求值表达式的值.
eval()
returns the value of the last expression evaluated.
因此,简而言之,它将评估表达式中对console.log
的所有调用,然后还记录eval
-ed表达式本身的返回值,而该返回值恰好是最后一个i++
的结果.
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++
.
这篇关于Chrome DevTools:此箭头(< ;-)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!