DEV Community

Cover image for Javascript Data Types in Depth(1)
waqas
waqas

Posted on

Javascript Data Types in Depth(1)

what are data types
in computer programming, a data type is a classification of types of data that determines the possible values and operations that can be performed on that data. Data types are an essential concept in any programming language, as they provide a way for programmers to represent and manipulate data in a structured and organized manner.

Data types in JavaScript **
**Primitive and reference (non primitive)

1. Numbers
let num =100;

2.strings
let str=hello world

3. boolean
let present =True

4.Undefined
let myundefined = undefined

5.Null
let mynull=Null

When a variable with a primitive data type is created, the value of that data type is directly stored in the memory allocated for the variable.
For example, if you have a string variable called 'myString' with the value "Hello", the string value "Hello" is directly stored in the memory allocated for the 'myString' variable. This means that the amount of memory required to store a primitive value is equal to the size of the value itself.

However, this does not mean that you can change the value of the string directly. As I mentioned earlier, primitive data types in JavaScript are immutable, which means they cannot be changed once they have been created. This means that if you want to change the value of a string, you have to create a new string with the new value, and then assign that new string to the same variable.

var myString = "Hello"; // Create a string variable with the value "Hello"
myString = "Goodbye"; // Create a new string with the value "Goodbye" and assign it to the same variable

So, to summarize, it is possible to update the value of a variable with a primitive data type in JavaScript. However, this does not change the value of the primitive data type itself, which remains immutable. It is only reference data types that are mutable and can be directly modified.

Top comments (2)

Collapse
 
jonrandy profile image
Jon Randy 🎖️

You've missed bigint and symbol in the primitive data types

Collapse
 
waqasongithub profile image
waqas

im gonna edit soon thanks