DEV Community

Cover image for JavaScript Primitive & Non Primitive Data Type
Omar Adel
Omar Adel

Posted on

JavaScript Primitive & Non Primitive Data Type

Normally when we hear data types in any programming language, integer, string, etc... jumps to our mind.

Although all of these things are data types, there are two umbrellas contains most of the JavaScripts data types.

Primitive Data Types & Non Primitive Data Types

Non Primitive Data Types

  • Array which is used for storing different elements, Ex:
arr = [1, 3, 5, 'jack']
Enter fullscreen mode Exit fullscreen mode
  • Object which is a standalone entity, with properties and type, Ex:
client = {
  name: "Harry Potter",
  age: 20,
  eyeColor: "blue"
};
Enter fullscreen mode Exit fullscreen mode

Primitive Data Types

  • Number which is used for floating-point numbers, Ex:
num = 1;
Enter fullscreen mode Exit fullscreen mode
  • String which is used for sequence of characters, Ex:
name = 'Mike';
Enter fullscreen mode Exit fullscreen mode
  • Boolean which is used for logical type that can be only true or false, Ex:
flag = true;
Enter fullscreen mode Exit fullscreen mode
  • Undefined which is used for a variable that got declared and yet not assigned to a value (empty value), Ex:
value;
console.log(value)     // undefined
Enter fullscreen mode Exit fullscreen mode
  • Symbol (ES2015) which is used for value that is unique & cannot be changed, Ex:
client = {
  name: "Harry Potter",
  age: 20,
  eyeColor: "blue"
};
id = Symbol('id');
client[id] = 101959; // you added an id to client named 'Harry Potter'
Enter fullscreen mode Exit fullscreen mode
  • BigInt (ES2020) which is used for larger integers than the number type can hold, Ex:
bigNum = BigInt("123456789012345678901234567890123456789");
Enter fullscreen mode Exit fullscreen mode

Note:

in both the array & the object can contain different types of data.

Top comments (2)

Collapse
 
jonrandy profile image
Jon Randy ๐ŸŽ–๏ธ

You've missed null in the primitive types

Collapse
 
omaradelattia profile image
Omar Adel • Edited

yeah thanks for reminding me