JavaScript handles different kinds of values in different ways, and this behavior depends completely on data types in JavaScript.

    Whenever you create a variable, JavaScript automatically decides what type of value it stores.If you understand this concept clearly, then you will avoid many common coding mistakes and, as a result, write much cleaner programs.

    In this guide, I will explain everything in a simple and practical way so that, even if you are a complete beginner, you can confidently understand the concept step by step.

    What Exactly Are Data Types in JavaScript?

    In simple words, a data type inform to JavaScript what kind of value a variable holds.

    For example –

    • “Hello” is text.
    • 25 is a number.
    • True is a logical value.

    JavaScript treats all of them differently. That’s why understanding data types in JavaScript is very important before moving to advanced topics.

    Two Main Categories of Data Types in JavaScript

    JavaScript divides data types into two major categories, which are –

    1. Primitive Data Types
    2. Reference (Non-Primitive) Data Types

    Let’s break them down properly with details.

    Primitive Data Types

    Primitive data types store a single value. They are simple and straightforward. When you copy them, JavaScript copies the actual value.

    JavaScript provides 7 primitive types to us –

    1. String
    2. Number
    3. Boolean
    4. Undefined
    5. Null
    6. BigInt
    7. Symbol

    Now, let’s understand each one clearly with examples.

    1. String (Text Values)

    A string stores text. You write it inside quotes.

    // Storing a name as string
    
    let userName = "David";
    
    console.log(userName);
    
    // Output: David

    You can use single quotes, double quotes, or backticks with string in JS.

    Developers use strings to store names, messages, emails, and other text-based data.

    2. Number (Numeric Values)

    The number type stores integers and decimal values in JS.

    // Storing numbers
    
    let age = 30;
    
    let price = 99.99;
    
    console.log(age);   // 30
    
    console.log(price); // 99.99

    Please note that JavaScript does not separate integers and floats. It treats both as Number.

    3. Boolean (True or False)

    Boolean values help you control logic in your program.

    // Boolean values
    
    let isLoggedIn = true;
    
    let isAdmin = false;
    
    console.log(isLoggedIn);
    
    // true

    You mostly use booleans in conditions and decision-making.

    4. Undefined

    When you declare a variable but do not assign a value, JavaScript sets it to undefined.

    // Variable declared but not assigned
    
    let score;
    
    console.log(score);
    
    // undefined

    This means the variable exists, but it does not contain any value yet.

    5. Null

    Null represents an intentionally empty value.

    // Intentionally clearing value
    
    let selectedUser = null;
    
    console.log(selectedUser);
    
    // null

    Use null when you want to reset or clear a variable.

    Important –
    Null and undefined are not the same; this question is very important for JS interviews.

    6. BigInt

    BigInt stores very large numbers that exceed the safe limit of normal numbers.

    // BigInt example
    
    let largeNumber = 123456789012345678901234567890n;
    
    console.log(largeNumber);

    Notice the n at the end. Without it, JavaScript will treat it as a normal number.

    7. Symbol

    Symbol creates a unique value. Developers mostly use it in advanced scenarios.

    // Creating a unique symbol
    
    let userId = Symbol("id");
    
    console.log(userId);

    Every symbol you create stays unique.

    Reference (Non-Primitive) Data Types in JavaScript

    Reference types store complex data. Instead of copying the value, JavaScript copies the reference.

    The main reference type is Object. Arrays and functions also fall under this category.

    1. Object

    An object stores data in key-value pairs.

    // Object example
    
    let user = {
    
      name: "David",
    
      age: 28,
    
      isPremium: true
    
    };
    
    console.log(user.name);
    
    // David

    Objects help you organize related information together.

    2. Array

    An Array in JavaScript stores multiple values inside a single variable.

    // Array example
    
    let colors = ["red", "green", "blue"];
    
    console.log(colors[1]);
    
    // green

    Arrays make it easy to manage lists of items.

    3. Function

    Functions are also objects in JavaScript.

    // Function example
    
    function greet() {
    
      console.log("Welcome to JavaScript");
    
    }
    
    greet();

    Functions allow you to reuse code instead of repeating it.

    Quick Summary Table

    Data Type Category Example Use Case
    String Primitive “Hello” Store text
    Number Primitive 100 Store numeric values
    Boolean Primitive true Control logic
    Undefined Primitive undefined Unassigned variable
    Null Primitive null Empty value
    BigInt Primitive 123n Large numbers
    Symbol Primitive Symbol() Unique identifiers
    Object Reference {name: “John”} Structured data
    Array Reference [1,2,3] List of items
    Function Reference function(){} Reusable logic

    How to Check Data Types in JS

    You can use the typeof operator to check the data types of any value.

    console.log(typeof "Hello"); 
    
    // string
    
    console.log(typeof 25);      
    
    // number
    
    console.log(typeof true);    
    
    // boolean

    One important thing –

    console.log(typeof null);
    
    // object

    This is a historical bug in JavaScript. Do not let it confuse you.

    Primitive vs Reference – Simple Difference

    Primitive types copy actual values –

    let a = 10;
    
    let b = a;
    
    b = 20;
    
    console.log(a);
    
    // 10

    Reference types copy memory reference:

    let obj1 = { name: "David" };
    
    let obj2 = obj1;
    
    obj2.name = "Mike";
    
    console.log(obj1.name);
    
    // Mike

    This difference is very important in real projects.

    Common Mistakes that Beginners Make

    1. Mixing strings and numbers.
    2. Confusing null and undefined.
    3. Forgetting that arrays are objects.
    4. Not understanding reference copying.

    Avoid these mistakes and your code will become much more stable.

    Final Thoughts

    Now you clearly understand how data types in JavaScript work and why they matter in every program you write. If you master data types –

    • You reduce bugs.
    • You understand memory behavior.
    • You write better logic.
    • You debug faster.

    Every strong JavaScript developer builds a solid foundation first. Data types are part of that foundation.

    Now open your editor and start experimenting with different values. Practice will make everything clearer.

    Read Also –

    1- Hoisting in JavaScript
    2- this Keyword in JavaScript
    3- For Loop in JavaScript

    Share.

    Vijay Chauhan is a tech professional with over 9 years of hands-on experience in web development, app design, and digital content creation. He holds a Master’s degree in Computer Science. At SchoolUnzip, Vijay shares practical guides, tutorials, and insights to help readers stay ahead in the fast-changing world of technology.

    Leave A Reply