Primitive data types are the most basic data types in JavaScript. They are immutable (their values cannot be changed directly; operations on them create new values).
-
String
: Represents textual data. Enclosed in single quotes ('...'
), double quotes ("..."
), or backticks (`...`
- template literals).let greeting = "Hello"; let name = 'Alice'; let message = `Welcome, ${name}!`; // Template literal with interpolation
-
Number
: Represents both integer and floating-point numbers. JavaScript has only one number type.let integerNum = 100; let floatNum = 3.14; let scientificNum = 2.5e6; // 2.5 * 10^6
Special numeric values:
Infinity
,-Infinity
,NaN
(Not a Number). -
BigInt
: Represents integers of arbitrary length. Created by appendingn
to the end of an integer literal or by callingBigInt()
.let largeNumber = 123456789012345678901234567890n; let anotherBigInt = BigInt("98765432109876543210");
-
Boolean
: Represents a logical entity and can have two values:true
orfalse
.let isActive = true; let isLoggedIn = false;
-
undefined
: A variable that has been declared but not yet assigned a value has the valueundefined
.let myVar; console.log(myVar); // Output: undefined
-
null
: Represents the intentional absence of any object value. It is an assignment value, meaning it can be assigned to a variable as a representation of no value.let emptyValue = null;
-
Symbol
(ES6+): A unique and immutable primitive value that may be used as the key of an Object property. Less common in everyday beginner scripting.