Engineering Core
ISB Vietnam's skilled software engineers deliver high-quality applications, leveraging their extensive experience in developing financial tools, business management systems, medical technology, and mobile/web platforms.

When working with languages like JavaScript, Java, C#, Python, and many others, you will always encounter two fundamental concepts: Value Types and Reference Types. They may sound a bit technical, but they simply describe how data is stored in memory and how it behaves when assigned to variables or passed to functions.

Understanding the difference helps you avoid unexpected bugs and write cleaner, more predictable code.
In this post, we’ll explore:
    • What Value Types are
    • What Reference Types are
    • Why the difference matters
  • Common bugs caused by misunderstanding the two
  • Practical examples (JavaScript and C#)

1. What Is a Value Type?

A Value Type stores the actual value directly in memory (typically on the stack).
Key behavior: When you assign a Value Type to another variable, the value is copied. The two variables become completely independent.
Common Value Types
  • Number (int, float…)
  • Boolean
  • Char
  • Struct (C#)
  • Enum
Example (JavaScript)

let a = 10;
let b = a; // b receives a copy
a = 20;

console.log(a); // 20
console.log(b); // 10
Explanation: b holds its own copy of the value, so changes to a do not affect it.

2. What Is a Reference Type?

A Reference Type stores a reference (memory address) that points to data located on the heap.
Key behavior: Assigning a Reference Type to another variable copies the reference, not the actual data. Both variables point to the same object in memory.
Common Value Types
  • Object
  • Array
  • Function
  • Class instances
  • Collections (List, Dictionary, Map…)
Example (JavaScript)

let obj1 = { name: "David" };
let obj2 = obj1; // both point to the same object

obj1.name = "Alex";

console.log(obj1.name); // Alex
console.log(obj2.name); // Alex
Explanation: Both variables refer to the same object in memory.

3. Value Types vs Reference Types: Visual Summary

Feature Value Type Reference Type
Stored in Stack Heap (reference on stack)
What is stored Actual value Address pointing to data
Assignment behavior Copies the value Copies the reference
Independence between variables Yes No
Examples int, float, bool object, array, class

4. Shallow Copy vs Deep Copy

When dealing with Reference Types, copying becomes more complex.

Shallow Copy

Copies only the top-level structure; nested objects still share references.

Deep Copy

Copies all levels of data; nothing is shared.
Example (JavaScript deep copy):

let obj1 = { name: "Dũng", info: { age: 30 }};
let obj2 = structuredClone(obj1);

obj1.info.age = 31;

console.log(obj2.info.age); // 30 (independent)

5. Final Thoughts

Key takeaway
  • Value Types store actual values
  • Reference Types store memory references
  • Copying a Value Type creates an independent variable
  • Copying a Reference Type creates shared memory
  • Copying a Reference Type creates shared memory
Understanding these concepts will help you write more predictable, bug-free code—especially when dealing with objects, arrays, or complex data structures
Whether you need scalable software solutions, expert IT outsourcing, or a long-term development partner, ISB Vietnam is here to deliver. Let’s build something great together—reach out to us today. Or click here to explore more ISB Vietnam's case studies.
Written by
Author Avatar
Engineering Core
ISB Vietnam's skilled software engineers deliver high-quality applications, leveraging their extensive experience in developing financial tools, business management systems, medical technology, and mobile/web platforms.

COMPANY PROFILE

Please check out our Company Profile.

Download

COMPANY PORTFOLIO

Explore my work!

Download

ASK ISB Vietnam ABOUT DEVELOPMENT

Let's talk about your project!

Contact US