Sumit | Javascript + React
Sumit | Javascript + React

@sumitsaurabh927

9 Tweets 4 reads Apr 05, 2023
Javascript has 100s of concepts.
But not all of them are important for web development.
However, some are fundamental concepts that one absolutely MUST know.
This is one of them - data types in Javascript
A thread ๐Ÿงต
There are fundamentally two data types in Javascript:
1๏ธโƒฃ Primitive data type
2๏ธโƒฃ Reference data type ( or non primitive)
Now, let's look at each one of them in detail......๐Ÿ‘‡
๐Ÿ“Œ Primitive data type:
โžก๏ธ A primitive data type is one where the size of data type is fixed.
๐ŸŒŸ Ex - When we say let num = 2; the computer creates a finite space in RAM to store the value
๐Ÿช„ When we update num to some other value, it directly updates this stored data.
๐ŸŽฏ Also, in the case of primitive data types, the computer accesses the value in the memory location directly.
๐Ÿ‘‰ Common examples of primitive data types are: Boolean, Number, String etc
๐Ÿ“Œ Reference data type:
โœ… Unlike primitive data type, when we create a variable to store a reference data type, the address of the data is stored in the variable and not the data itself.
Let me explain this a bit more...๐Ÿ‘‡
๐ŸŽฏ When we create reference data type variable, as:
let myObj = {name: 'Sumit'}
๐Ÿ›ก๏ธ Here 'myObj' doesn't have the object itself.
โžก๏ธ It, rather, points to a memory location where the actual object (with name:'Sumit') is stored.
๐Ÿ’ก Contrast this with 'num' variable above which directly stores the value.
๐ŸŒŸ So, primitive data type directly store the value whereas reference data type store the value's address in memory and not the value itself.
โœ… This is why they're called 'reference' as the address stored serves as a reference to the actual value.
๐Ÿ—ƒ๏ธ Also, primitive data types have fixed sizes while reference data types' size is dynamic.
I write threads daily on web dev so if you enjoyed this thread, please:
โœ… Follow me @sumitsaurabh927 for more of these.
โค๏ธ Each like, every comment of y'all motivates me to come up with awesome new stuff!
โœ… RT the tweet below to show me some love.

Loading suggestions...