On this page

JavaScript Primitive Data Types

Enrico Hochkoeppler Profile

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.


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.


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.


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.


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.


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 typeof operator. Be aware of a famous JavaScript quirk: typeof null returns "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!

Buy Me a Coffee

Previous

Variables declaration in JavaScript

Next

Arithmetic & Logical Operators