JavaScript Data Types

# beginners# javascript# programming# tutorial
JavaScript Data TypesAdhi sankar

Introduction JavaScript is one of the most popular programming languages used to create interactive...

Introduction

JavaScript is one of the most popular programming languages used to create interactive and dynamic web applications. Every program works with data, and JavaScript provides different data types to store and manipulate that data efficiently.

JavaScript data types are broadly classified into two categories:

Primitive Data Types
Non-Primitive (Reference) Data Types

Let's explore each of them in detail.

Primitive Data Types

Primitive data types store a single value and are immutable, meaning their actual values cannot be changed directly.

1. Number

The Number data type represents both integer and decimal values.

Example
let age = 21;
let price = 99.99;

console.log(age);
console.log(price);

Output

21
99.99
2. String

A String represents textual data enclosed in single quotes (''), double quotes (""), or backticks (


`).

**Example**
let name = "Adhi";
let city = 'Chennai';

console.log(name);
console.log(city);

**Output**

Adhi
Chennai
**3. Boolean**

A Boolean can have only two values:

true
false

It is mainly used in decision-making.

**Example**
let isStudent = true;
let isLoggedIn = false;

console.log(isStudent);
console.log(isLoggedIn);

**Output**

true
false
**4. Undefined**

A variable that has been declared but not assigned any value has the value undefined.

**Example**
let course;

console.log(course);

**Output**

undefined
**5. Null**

null represents the intentional absence of a value. It means the variable is empty by choice.

**Example**
let user = null;

console.log(user);

**Output**

null
**6. BigInt**

BigInt is used to store integers larger than the maximum safe integer supported by the Number type.

**Example**
let bigNumber = 123456789012345678901234567890n;

console.log(bigNumber);
**7. Symbol**

A Symbol creates a unique value. It is commonly used to create unique object properties.

**Example**
let id1 = Symbol("id");
let id2 = Symbol("id");

console.log(id1 === id2);

**Output**

false
**Non-Primitive (Reference) Data Types**

Non-primitive data types can store multiple values and are stored by reference.

**1. Object**

Objects store data in key-value pairs.

Example
let student = {
    name: "Adhi",
    age: 21,
    department: "CSE"
};

console.log(student);
**2. Array**

An array stores multiple values in a single variable.

Example
let colors = ["Red", "Blue", "Green"];

console.log(colors);
**3. Function**

Functions are reusable blocks of code.

Example
function greet() {
    console.log("Welcome to JavaScript");
}

greet();
Checking Data Types

JavaScript provides the typeof operator to determine the type of a value.

**Example**
console.log(typeof 100);
console.log(typeof "Hello");
console.log(typeof true);
console.log(typeof undefined);
console.log(typeof null);
console.log(typeof {});
console.log(typeof []);

**Output**

number
string
boolean
undefined
object
object
object

**Conclusion**

Data types are the foundation of JavaScript programming. They define the kind of data that can be stored and manipulated in a program. JavaScript provides seven primitive data types—Number, String, Boolean, Undefined, Null, BigInt, and Symbol—and non-primitive data types such as Object, Array, and Function. 
Enter fullscreen mode Exit fullscreen mode