DEV Community

Cover image for What is Value Types and Reference Types in JavaScript
Yashraj
Yashraj

Posted on • Edited on

What is Value Types and Reference Types in JavaScript

Two fundamental categories that every developer should understand are value types and reference types. Value type is basically it will not changeable after something is assigned to variable and reference type is what we can change after declaration.

In JavaScript objects are reference type and all other data types are value types. It is important to know the difference between this to datatypes which will help you avoid common pitfalls and write more efficient code.

Value type example
let a = 10;
let b = a; // b is now 10
b = 20; // changing b does not affect a
console.log(a); // 10

Reference type example
let obj = { name: 'John' };
obj.name = 'Doe'; // the original object is modified
console.log(obj.name); // 'Doe'

Learn more...

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay