简体   繁体   中英

How does JavaScript store null values internally?

I always wondered how JavaScript stores null values internally. null is different than any value. I imagine that the scope's variables are stored in some kind of array of structures, each structure corresponding to a variable. Does this structure has some kind of boolean property called "null"?

I would look for it myself in the V8 source code, but am am pretty lost in the C++ code :(

I couldn't find anything on Google. Most results were related to questions like "How to determine if variable is undefined or null?" or similar.

JavaScript, being a weakly-typed scripting language, probably has a variant type that supports values of all kinds of types. I believe PHP uses the same type of variables, although they are known in other languages too and play an important role in COM automation.

They are basically structs that contain a type and a value. The value can be a simple value, or a pointer to a larger or more complex value. null is just one of the supported types, in which case the value itself plays no part.

But since JavaScript knows many interpreters, there is no rule about how it is implemented, and it is something you should not worry about. Normally you would only need to know about underlying techniques like this for time-critical applications, which should not by written in JavaScript anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM