This content originally appeared on 2ality – JavaScript and more and was authored by Dr. Axel Rauschmayer
This blog post is second in a series of two:
JavaScript has two kinds of values:
- primitive values (
undefined
,null
, booleans, numbers, bigints, strings, symbols) - objects (all other values)
The ECMAScript specification states:
A primitive value is a datum that is represented directly at the lowest level of the language implementation.
However, despite this fact, we can still use primitive values (other than undefined
and null
) as if they were immutable objects:
> 'xy'.length
2
This blog post answers the following question:
How do primitive values get their properties?
We’ll look at:
- Getting property values
- Invoking property values (a.k.a. method calls)
- Setting property values
Each time, we’ll first examine what’s going on via JavaScript code and then investigate how the language specification explains the phenomena.
Note that JavaScript engines only mimick the external behavior of the language specification. Some of what the spec does internally is not very efficient (e.g. wrapping primitive values) and often done differently in engines.
This content originally appeared on 2ality – JavaScript and more and was authored by Dr. Axel Rauschmayer
Dr. Axel Rauschmayer | Sciencx (2022-03-02T00:00:00+00:00) How do primitive values get their properties?. Retrieved from https://www.scien.cx/2022/03/02/how-do-primitive-values-get-their-properties/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.