Skip to content

Latest commit

 

History

History
118 lines (87 loc) · 2.98 KB

data-types.md

File metadata and controls

118 lines (87 loc) · 2.98 KB

⚑ Data Types

Data Types is used to mention that the variable holds specific type data to handle and process without an issue.

There are 3 common variables in JavaScript.

☴ Overview:

  1. Primitive Data Types
  2. Non-Primitive Data Types

✦ Primitive Data Types:

Primitive data types are the most basic building blocks of JavaScript. They represent individual piece of values, not objects.

The list of primitive data types are numbers, strings, booleans, null, undefined, symbols.

✦ Numbers:

It represents numerical values, including integers and floating-point numbers.

let age = 42; // Number Integer
let pi = 3.14; // Decimals Floating-point number

✦ Strings:

It represents sequences of characters.

let name = "Alice";
let message = "Welcome!";

✦ Booleans:

It represents true or false values.

let isAdult = true;
let isRaining = false;

✦ Null:

It represents the absence of a value.

let user = null; // Indicates that the user is not logged in

✦ Undefined:

It represents a variable that has not been assigned a value.

let result;
console.log(result); // Output: undefined

✦ Symbols:

It represents a unique identifier.

Syntax: let uniqueSymbol = Symbol("mySymbol");

const PRIVATE_KEY = Symbol("private");

✦ Non-Primitive Data Types:

Non-primitive data types in JavaScript are complex data structures that can hold multiple values or properties. They are mutable and compared by reference.

The list of non-primitive data types are arrays and objects.

✦ Arrays:

It is a ordered collections of elements.

Syntax: let array = [1, "hello", true];

let fruits = ["apple", "banana", "orange"];
let numbers = [1, 2, 3, 4, 5];

See More on this Reference

✦ Objects:

It is a collections of key-value pairs

let object = {
  name: "Alice",
  age: 30,
  isStudent: true
};

See More on this Reference

✦ Comparison:

  • Data type:
    • Primitive Data Types: It represent individual values and single piece of data.
    • Non-Primitive Data Types: It represent collections of data.
  • Mutability:
    • Primitive Data Types: immutable (their values cannot be changed directly).
    • Non-Primitive Data Types: objects are mutable (their properties can be modified).
  • Comparison:
    • Primitive Data Types: It compared by value.
    • Non-Primitive Data Types: It compared by reference.

⇪ To Top

❮ Previous TopicNext Topic ❯

⌂ Goto Home Page