Skip to main content

Command Palette

Search for a command to run...

Data Types In JavaScript

Updated
2 min read
Data Types In JavaScript
S
Relentlessly curious and fiercely high‑agency, I'm a senior software engineer who thrives on taking products from zero to production‑ready in record time. Having worked across startups and fast-paced organizations, I've built a reputation as a cracked engineer who solves hard problems fast and owns the entire product stack end-to-end. My knack for rapid problem‑solving and end‑to‑end ownership turns complex ideas into polished, scalable products that ship fast and scale even faster. phewww... I love a cup of coffee ☕ while writing code. So let's connect and have a meet over something you wanna discuss. I'll be more than happy to have it. Book a call with me: https://cal.com/xshivank

Introduction

There are two types of Data Types available in JavaScript:

  1. Primitive Data Type

  2. Non-Primitive Data Type

Primitive Data Types

Primitive Data Type refers to the Data Type in which data doesn't contain any object or method. For example- Number, String, Boolean, Symbol, Null, etc.

  • String: It refers to the sequence of characters that are present inside single or double quotes. For example-
var str1 = 'This is String 2';
var str2 = "This is String 1";
  • Number: It represents data in numerical form. For example-
var a = 100;
var b = 20.1;
  • Boolean: It represents a statement either as false or true. For example-
var x = 12;
var y = 12;
var z = 13;
console.log(x == y); //gives output as true
console.log(y == z); //gives output as false
  • Undefined: It is used when the user wants to declare a variable but doesn't want to assign any value to it. For example-
var a; //method 1
var b = undefined; //method 2
  • Null: It represents an invalid value. For example-
var value = null;

Non-Primitive Data Types

Non-Primitive Data Type refers to the Data Type which can store multiple and complex values.

  • Object: It is used for storing a collection of data items. For example-
 var obj1 = {
      a: 10, //stores data in Number
      b: 'Hi!', //stores data in String
      c: function(){
          return 'This is a JavaScript Object';
      }
}
  • Array: It is used for storing multiple Data Items under a single variable name. For example-
var arr = ['Hi',21,3.2,false];

I hope that you must have found this article quite helpful. If yes, then do give a read to some of my other articles!

Who knows you might become a great programmer 🤔!

More from this blog

Shivank Kapur

57 posts

learning distributed systems 🦀 / dev-rel eng @routerprotocol / member @superteam / previously @thedogecapital @pushprotocol