#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
JavaScript Fundamentals

Overview of Data types

A data type describes what kind of value something is: a number, a piece of text, true or false, an object and so on. JavaScript has eight data types. Seven are primitive, meaning simple values that cannot be changed, and one is the object type, which covers arrays, functions, dates and every other structured value. Variables in JavaScript do not have fixed types; the value inside them does.

The eight types at a glance

TypeExample valuesUsed for
Number42, 3.14, -7, NaN, InfinityIntegers and decimals alike.
BigInt12345678901234567890nWhole numbers too large for Number.
String'hello', "Asha", `Hi ${name}`Text.
Booleantrue, falseYes or no decisions.
UndefinedundefinedA variable declared but not given a value.
NullnullAn intentional "no value".
SymbolSymbol('id')Unique keys for object properties.
Object{ id: 1 }, [1, 2], new Date()Collections and structured data.

Checking types with typeof

console.log(typeof 42);            // "number"
console.log(typeof 'hi');          // "string"
console.log(typeof true);          // "boolean"
console.log(typeof undefined);     // "undefined"
console.log(typeof 10n);           // "bigint"
console.log(typeof Symbol());      // "symbol"
console.log(typeof { a: 1 });      // "object"
console.log(typeof [1, 2]);        // "object"  (arrays are objects)
console.log(typeof function () {});// "function" (a callable object)
console.log(typeof null);          // "object"  (a historic quirk)
console.log(typeof NaN);           // "number"

let value = 5;       // a number now
value = 'five';      // a string now: allowed, types belong to values
console.log(Array.isArray([1, 2]));  // true
console.log(value === null);         // the reliable null check

Primitives versus objects

The split between primitives and objects affects how values behave when you copy or compare them.

  • Primitives are copied by value. let a = 5; let b = a; b = 9; leaves a as 5. Primitives are also immutable: string methods like toUpperCase() return a new string instead of changing the old one.
  • Objects are shared by reference. const x = { n: 1 }; const y = x; y.n = 2; changes x.n too, because both variables point to one object.
  • Comparison follows the same rule. Two strings with the same text are equal. Two separate objects with identical contents are not: {} === {} is false.

Quirks worth memorising

typeof null returns "object". It is a long-standing mistake in the language that cannot be fixed without breaking old websites. To test for null, compare directly with value === null. To test for an array, use Array.isArray(), since typeof says "object".

NaN, meaning "not a number", is itself of type number. It appears after invalid maths like Number('abc'), and it is not equal to anything, even itself. Check it with Number.isNaN(value).

Finally, there is no separate integer type. 5 and 5.0 are the same Number. That is convenient, but it means very large integers lose precision, which is why BigInt exists.

undefined and null are not the same

JavaScript gives you undefined automatically: an unassigned variable, a missing object property or a function with no return. null is something you set on purpose to say "empty for now", for example clearing a selected item. Many teams use null for deliberate blanks and let undefined mean "never set".

Summary

JavaScript has seven primitive types and one object type. Primitives are copied and compared by value; objects by reference. Use typeof for most checks, but test null with === and arrays with Array.isArray. The next lesson goes through each primitive type in more detail.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course