JavaScript Data Types


In JavaScript, data types define the kind of value that a variable can hold and how it can be used. A data type determines the operations that can be performed on the variable and how it behaves when manipulated. For example, numbers can be used in mathematical calculations, while strings can be manipulated with text-based methods.

1. Number

Represents both integer and floating-point numbers.

let age = 25;

let price = 19.99;


2. String

Represents sequences of characters. Strings are enclosed in single quotes, double quotes, or backticks.

let name = ‘Alice’;

let greeting = “Hello, World!”;


3. Boolean

Represents logical values: true or false.

let isAvailable = true;

let hasLicense = false;


4. Undefined

Indicates a variable that has been declared but not assigned a value.

let x;

console.log(x); // undefined


5. Null

Represents the intentional absence of any object value. It is often used to indicate that a variable should have no value.

let y = null;


6. Symbol

Represents a unique identifier. Each Symbol is unique, even if they have the same description. Symbols are often used to avoid property name collisions in objects.

let sym1 = Symbol(‘foo’);

let sym2 = Symbol(‘foo’);

console.log(sym1 === sym2); // false


7. BigInt

Represents integers with arbitrary precision, which can be used for very large numbers.

let bigIntValue = 1234567890123456789012345678901234567890n;

 
Scroll to Top