Lesson 10 of 30 – JavaScript Data Types
33%

JavaScript Data Types

JavaScript allows you to store different kinds of data such as strings, numbers, booleans, arrays, and objects.

Note: JavaScript is a loosely typed language, meaning a variable can hold different types of values.
Introduction to Data Types

A variable can store different kinds of values.

Example:
let myvariable = 1;
myvariable = "one";
myvariable = true;

Here, the same variable stores a number, string, and boolean value.

Primitive Data Types

Primitive data types are the basic building blocks of JavaScript.

Type Description
String Stores text values.
Number Stores numeric values.
BigInt Stores very large integers.
Boolean Stores true or false.
Null Represents no value.
Undefined Variable declared but not assigned.
Structural Data Types

Structural data types can store multiple values.

Type Description
Object Stores properties and methods.
Date Represents date and time.
Array Stores multiple values.
Primitive Data Types - Key Features
Important Points:
  • Immutable: Their values cannot be changed after creation.
  • Fast Access: Stored directly in memory.
  • Simple Values: Hold a single value.

Primitive Types:
  • Number: Stores integers and decimal values.
  • BigInt: Stores very large numbers.
  • String: Stores text inside quotes.
  • Boolean: Stores true or false.
  • Undefined: Variable without a value.
  • Null: Represents an empty value.
  • Symbol: Stores unique identifiers.
Number Data Type

The Number data type stores integers and decimal values.

Example:
let age = 25;
let price = 99.99;

JavaScript uses the same Number type for whole and decimal numbers.

String Data Type

Strings are sequences of characters enclosed in quotes.

Example:
let name = "Soopro";
let city = 'Aurangabad';

Both single and double quotes are valid.

Boolean Data Type

Boolean values represent logical states.

Example:
let isPass = true;
let isFail = false;

Boolean values are mainly used in conditions.

Undefined and Null
Undefined
let x;

A variable declared without a value is undefined.


Null
let y = null;

Null represents an intentionally empty value.

Reference Data Types

Reference data types can store collections of data and are mutable.

  • Object: Collection of key-value pairs.
  • Array: Ordered collection of values.
  • Function: Reusable block of code.
  • Date: Stores date and time.
  • Map & WeakMap: Store key-value data.
  • Set & WeakSet: Store unique values.
Object Example

Objects store multiple related values.

let student = {
name:"Rahul",
age:20
};

Properties are accessed using dot notation.

Array Example

Arrays store multiple values in a single variable.

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

Each value has an index starting from 0.

Key Points
  • JavaScript is loosely typed.
  • Variables can hold different data types.
  • Primitive data types store single values.
  • Reference data types store collections of values.
  • Objects and arrays are mutable.
  • Undefined means no value assigned.
  • Null represents an empty value.
Best Practices
  • Choose appropriate data types.
  • Use const whenever possible.
  • Use meaningful variable names.
  • Avoid unnecessary type conversions.
  • Understand primitive and reference types.
  • Keep code simple and readable.

🧠 Quick Quiz

Which JavaScript data type stores true or false values?