Answer the question
In order to leave comments, you need to log in
What are the actual data types in javascript?
Hello!
As I understand it, there are two main data types in js (conditionally). These are primitive data types and objects.
Primitives are immutable, for example we have a string, we need to add a few more characters to it, so we concatenate.
let str = 'Hello'
let result = str + 'Vova'
Answer the question
In order to leave comments, you need to log in
As I understand there are two main data types in js
What happens to the data type when str is concatenated with the string 'Vova' ?nothing happens to the data type. The value is new, at least it should be according to the spec and this is how it looks for an ordinary js developer.
The question is, are primitives overwritten if some operations are performed on them? I'm interested in the creation algorithm itself, what happens insidePrimitives are never overwritten, at least while they are "alive" (until garbage collection recognizes them as garbage due to the lack of references to the memory where they lie). All manipulations with variables under the hood are almost always (I will write about when not - I will write below) simple manipulations over pointers (references).
Are primitive types objects?From the point of view of the specs - no, they are not. They should have object wrappers when their fields are accessed (through a dot or square brackets).
1. A new result variable with the string type simply appears, which has nothing to do with str.
The type of a variable in js is determined at the time of assignment, not at the time of declaration. Each time you assign a new value to it, its type is determined.
2. "Variable" is just a property of a special internal object: Environment Record. "Get or change a variable" means "get or change a property of this object".
3. No. In this case, it can be confusing that in js it is possible to call a method on a primitive (For example, toUpperCase() on a string), this is possible because each primitive has a "wrapper object" that appears at the moment the variable is accessed (After is removed).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question