Before reading this article, you must have intermediate knowledge of
Here we will see about,
- Data types & a Variable
- Primitive type vs reference type
- Literal vs reference (Object, Function, Array)
If you are familiar with programming languages like,
- Number > integer, BigInt, floats etc.
- String > Array of characters i.e words
- Boolean > True/false
- Null > no value (technically null is a value)
- undefined > not defined at declaration time
- symbol > a unique value that is not equal to another value
boolean you just simply tells to the computer about declaring of data not the form of the data.
typeof keyword/operator. let's break here about types of data because this is not our main topic.
In the above visual piece of code, we have covered the variable also. Furthermore, a variable is the part of the memory for storing some kind of data. eg.
let name = 'Hawking'; now variable
name has space in memory containing data
Whatever we saw above
Data Types & a Variable these were primitive type of data which means whenever memory stores, this data will save an unordered way (where ever memory sees space put there) but in reference case memory store whole data in sequence order (with memory reference) you know why? because reference type of variables are
Function and an
Object. So, these types store in memory with sequence and generate reference (address) in the memory cell. This is the fundamental difference between primitive and reference data types.
In other words, reference type means the two reference types are objects and arrays (technically one, since arrays are objects). When you create an object, that value is not directly assigned to the variable. Instead, a reference to that value is what gets set. All that variable knows about is the location of the object in memory, not the object itself.
Now see how primitive and reference works on memory side.
(Object, Function, Array)
somehow both literal vs reference are the same thing but literal is a way to make a prototype of your data in an object, function, array form, and reference form has already designed a prototype of and can be accessible with
both codes have the same work but different in structural nature during declaration. In this case, I just create reference object but you can make reference
Array also by writting
That's all about reference vs literal. If you have any query you can ask me at any time.