'undefined' - 如果它被定义为原始值,那么它在内存级别的值是什么定义的?

'undefined' - if it's defined as a primitive value, what is it defined in terms of its value at the memory level?

我从 MDN 了解到 'undefined' 被识别为原始值,ES doco 证实了这一点,还指出 "undefined value" 是 "primitive value used when a variable has not been assigned a value"。

我也明白,即使变量可能没有被赋值(即未初始化变量),内存仍然被分配它在执行发生之前创建其执行上下文('creation' 阶段)期间。这解释了为什么当我们尝试访问变量时,我们没有收到引用错误 - 而只是遇到 'undefined'(即在控制台日志中)。

注意到上面的内容,我的问题是,在内存中,变量的内存位置是什么样的?在未定义变量的分配内存 location/address 处实际上是否存在 value或者是内存地址empty处的值(什么都没有)?如果是这样,我们是否可以将该值描述为 null (0x00)?

谢谢。

I also understand even though the variable may not be assigned a value (i.e. an uninitialised variable), memory is still allocated for it during the creation of its execution context ('creation' phase) prior to execution happening. This explains why when we attempt to access the variable, we do not get a reference error - rather we just encounter 'undefined'.

没有。未初始化的变量与使用值 undefined 初始化的变量不同。看看 .

What does this look like at the memory location of the variable?

如何实现并不重要。每个实现可能会有所不同,重要的是在 JS 中可观察到的效果。

Is there actually a value at the allocated memory location/address of the variable, or is the value at the memory address empty?

分配的内存总是有一些价值。不过,它可能是一个在 JS 中不存在表示的值。