Is a boolean
stored as a 32-byte integer in memory? How about a null
value?
In the book Speaking Javascript,
it refers to a type tag being used to indicate the type of a value stored in memory. e.g. The type tag for Object
type was 000. What is a type tag?
How would I find the type tag of a value type such as a boolean
or string
?
From Andy Wingo's blog post on the topic:
So the type tags allow for all values to be stored uniformly. All values occupy one machine word (32/64 bit) and depending on the tag (which is the least significant bit or bits) they are interpreted either as a pointer to an object or as some integer/boolean/etc depending on the tag.
A boolean also occupies one word. For a more specific answer I'd need to go though the v8 source. But if I remember correctly,
true
andfalse
are represented as root pointers.No way to do it from JavaScript. It's internal implementation details.