JavaScript Primitive data types represent a single value and are not an object. It includes Number, String, Boolean, Undefined, Null, Symbol, etc.
List of primitive data types in JS.
- String: represents a sequence of characters, enclosed in quotes (either single or double).
- Number: represents both integer and floating-point numbers.
- Boolean: represents a logical value of either
true
orfalse
. - Undefined: represents a variable that has been declared but has not been assigned a value. Example:
let x;
- Null: represents a variable that has been explicitly assigned the value of
null
. Example:let y = null;
- Symbol: represents a unique identifier that can be used as the key of an object property. Example:
const id = Symbol('id');
. - bigint: BigInt is a numeric data type in JavaScript that was introduced in ECMAScript 2020. It is used to represent integers that are larger than the maximum safe integer that can be represented by the Number data type, which is 2^53 – 1 (or 9,007,199,254,740,991).
Primitive data types in JavaScript example
Simple example code.
<!DOCTYPE html>
<html>
<body>
<script>
let message = "Hello, World!"; // String
console.log(message)
let age = 42; // Number
console.log(age)
let isStudent = true; // Boolean
console.log(isStudent)
let x; // Undefined
console.log(x)
let n = null; // Null
console.log(n)
const id = Symbol('id'); // Symbol
console.log(id)
</script>
</body>
</html>
Output:
These data types are called “primitive” because they are not objects and have no methods or properties of their own. However, JavaScript automatically converts primitive values to objects when necessary, using a process called “boxing”.
Comment if you have any doubts or suggestions on this Js data type topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version