JS Guide
HomeQuestionsSearchResources
Search

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsjavascript
PrevNext
javascript
junior
data-types

What are the primitive data types in JavaScript?

data-types
primitives
typeof
fundamentals
Quick Answer

JavaScript has 7 primitive data types: string, number, bigint, boolean, undefined, null, and symbol.

Detailed Explanation

Primitive data types are immutable and stored directly in memory. JavaScript has 7 primitives:

1. String - Textual data enclosed in quotes 2. Number - Integer and floating-point numbers (64-bit floating point) 3. BigInt - Integers of arbitrary length (suffix with 'n') 4. Boolean - true or false 5. Undefined - Variable declared but not assigned a value 6. Null - Intentional absence of any object value 7. Symbol - Unique and immutable identifier (ES6)

Everything else in JavaScript is an object (arrays, functions, objects, etc.).

Code Examples

Primitive types examples
// String
const str = 'Hello World';

// Number
const num = 42;
const float = 3.14;

// BigInt
const big = 9007199254740991n;

// Boolean
const bool = true;

// Undefined
let undef;
console.log(undef); // undefined

// Null
const empty = null;

// Symbol
const sym = Symbol('description');

Real-World Applications

Use Cases

Form Validation

Using typeof to check user input types before processing or submitting data

Feature Flags

Boolean primitives for enabling/disabling features in applications

Financial Calculations

Using BigInt for handling large integers beyond Number.MAX_SAFE_INTEGER in currency or cryptographic operations

Unique Object Keys

Using Symbol to create private-like properties that won't conflict with other code

Mini Projects

Type Checker Utility

beginner

Build a robust typeof wrapper that correctly handles null, arrays, and other edge cases

Primitive vs Reference Demo

intermediate

Create a visualization showing pass-by-value vs pass-by-reference behavior

Industry Examples

TypeScript

Extends JavaScript's type system with static typing built on primitive type foundations

JSON

JSON.parse returns primitives (strings, numbers, booleans, null) from JSON data

React

PropTypes library validates component props using primitive type checks

Resources

MDN - Data types and data structures

docs

JavaScript.info - Data types

article
Previous
What is the difference between var, let, and const in JavaScript?
Next
What is the difference between map(), filter(), and reduce() array methods?