YDKJS up & going 非原始平等
YDKJS up & going non-primitive equality
有人可以解释一下 YDKJS 中的以下段落,像我五岁一样走向我:
You should take special note of the == and === comparison rules if
you're comparing two non-primitive values, like objects (including
function and array). Because those values are actually held by
reference, both == and === comparisons will simply check whether the
references match, not anything about the underlying values. For
example, arrays are by default coerced to strings by simply joining
all the values with commas (,) in between. You might think that two
arrays with the same contents would be == equal, but they're not:
var a = [1,2,3];
var b = [1,2,3];
var c = "1,2,3";
a == c; // true
b == c; // true
a == b; // false
“参考”是什么意思?这是否意味着数组在内存中的位置?
嗯,是的,
例如,当您创建名为 'arr' 的数组时,您会看到。
你的记忆看起来像这样:
所以引用比较实际上检查数组引用是否指向堆中的相同数组。
堆栈用于值类型和引用。
有人可以解释一下 YDKJS 中的以下段落,像我五岁一样走向我:
You should take special note of the == and === comparison rules if you're comparing two non-primitive values, like objects (including function and array). Because those values are actually held by reference, both == and === comparisons will simply check whether the references match, not anything about the underlying values. For example, arrays are by default coerced to strings by simply joining all the values with commas (,) in between. You might think that two arrays with the same contents would be == equal, but they're not:
var a = [1,2,3]; var b = [1,2,3]; var c = "1,2,3"; a == c; // true b == c; // true a == b; // false
“参考”是什么意思?这是否意味着数组在内存中的位置?
嗯,是的,
例如,当您创建名为 'arr' 的数组时,您会看到。
你的记忆看起来像这样:
所以引用比较实际上检查数组引用是否指向堆中的相同数组。 堆栈用于值类型和引用。