- Courses
- 💻Programming Languages
- 🌐JavaScript
- Foundations
- Primitive Data Types
On this page
JavaScript Primitive Data Types
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
In modern web development, understanding how data is categorized is vital. In JavaScript, a Primitive is data that is not an object and has no methods. Understanding these is the first step toward writing clean, bug-free code and mastering JavaScript fundamentals.
There are five primary primitive data types you need to know: Strings, Numbers, Booleans, Null, and Undefined.
Strings (Representing Text)
A JavaScript String is used to represent textual data. You create strings by wrapping your text in single quotes (' '), double quotes (" "), or backticks ( ). Strings are immutable, meaning once created, the individual characters cannot be changed directly.
- Key Concept: Used for names, messages, and HTML content.
- Example:
const framework = "Vanilla JS";
const message = "Welcome to the course";
Numbers (Mathematical Values)
Unlike other languages that distinguish between integers and decimals, the JavaScript Number type handles both. Whether it’s a whole number like 10 or a float like 10.5, JavaScript treats them as the same type using 64-bit binary format.
- Key Concept: Used for any mathematical calculation or numeric ID.
- Example:
let totalScore = 100;
let conversionRate = 0.75;
Booleans (Logical Logic)
The Boolean type represents a logical entity and can have only two values: true or false. These are essential for conditional statements and controlling the flow of your application.
- Key Concept: Think of these as "On/Off" switches for your code logic.
- Example:
let isCourseCompleted = false;
let hasAccess = true;
Null (Intentional Absence)
In JavaScript programming, null is an assignment value. It is used by developers to represent the intentional absence of any object value. If you want a variable to be "empty," you assign it null.
- Key Concept: A deliberate way to say "this variable currently has no value."
- Example:
let userSelection = null; // Value will be assigned later by user action
Undefined (Uninitialized State)
A variable is undefined when it has been declared but has not yet been assigned a value. While null is something you assign, undefined is usually the default state the JavaScript engine gives to variables.
- Key Concept: Indicates a variable exists but hasn't been "filled" yet.
- Example:
let futureValue;
console.log(futureValue); // Results in undefined
Quick Reference: Primitive Comparison Table
Data TypeSEO KeywordPurposeExampleStringTextual DataStoring text/characters"Hello"NumberNumeric ValueMath and counting42BooleanLogical ValueTrue/False decisionstrueNullIntentional NullExplicitly emptynullUndefinedUninitializedDeclared but not setundefined
Pro-Tip for Developers: To check the type of a variable at runtime, use the
typeofoperator. Be aware of a famous JavaScript quirk:typeof nullreturns"object". While technically a bug in the language's original design, it was never changed to maintain backward compatibility!
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Variables declaration in JavaScript
Next
Arithmetic & Logical Operators
- Strings (Representing Text)
- Numbers (Mathematical Values)
- Booleans (Logical Logic)
- Null (Intentional Absence)
- Undefined (Uninitialized State)
- Quick Reference: Primitive Comparison Table
