Primitive vs Reference types
Expression and Statement
Before I proceed with the discussion, I will love to brief you on the history of how the English/German word primitive was use to classify some set of data types. Back in the early days of programming, programmers/coders/developers/engineers used to store values to a variable be it 1000 values, they will create variables for each of those values. But as development went on, some smart persons thought that why don't we store some values as a group because it doesn't make sense storing values of the same data-type in different variables. So they came about the array and as time goes on, they thought about storing values that belong to one single program or variable as objects or property of that variable or program and that was how OOP got their shot from.
I guess now you have remembered how the word primitive came about (Something related to early days). Now let's proceed!
From the material you have re(a)d or from the google explanation, you will see something like this:
Wow its quite interesting that bigInt has now been added as a primitive data-type in js but mind you, it's still classified as a number!
From my own definition, a primitive data-types are those data that get allocated into the RAM space(an area in the memory called the stack(an area that is small compared to the heap where reference types are stored)) with respect to its variable name. The example of the primitive types is a string, number, boolean, null, undefined, symbol, and object.
So what's my point here?
My point here is that any data that gets into a stack-space and a name is been allocated to it inside the stack for easy access, that data is a primitive data type. So the argument here is that; are reference types an implicit-primitive type? The answer is YES!!! But you will never see a material telling you that objects and arrays are primitive types(a lot of historical bug in programming and in this article we will find out some of them just be calm and follow).
So what are reference types?
The above picture is another one from google, which i guess is a bit unclear but never mind we will figure it out right away.
My short description of reference types is that: a reference type is a type of data in which its process of storage is divided into two phases: the primitive phase(the super phase) and the reference phase(supperless phase). The primitive phase holds the main data of the external variable and The reference phase holds the external variable that holds the properties inside the Primitive area(The stack). Note, all that the reference phase knows is just the location the values are stored inside the Primitive phase.
It's okay to be confused with all those foo-bar-baz but let's look at the code snippet with explanations below:
So, I hope you have a bit clue of how data management works between the primitive and reference type? But always remember that the heap holds the pointers whos main value resides inside the stack memory.
I could remember when i started writing java, all the documentation and lectures I had, I ended up coming up with the below analogy which is true!:
So you bring an expression together to perform an action in your program. So note; that when you just declare and define a variable, it's just an expression and ones you use it in another section with another variable but it mustn't be another variable (maybe just a simple concatenation), it becomes a statement