JavaScript size

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

set.size is the number of unique values in a Set.

JavaScript Syntax

JavaScript
const s = new Set([1, 1, 2]);
console.log(s.size);
s.add(3);
console.log(s.size);
Try it Editor

How It Works

  1. Unique. Duplicate 1 ignored → size 2.
  2. add. size becomes 3.

Examples

Example 1 — After clear

size is 0.

JavaScript
const s = new Set([1]);
s.clear();
console.log(s.size);
Try it Editor

How It Works

  1. clear removes all values.

Frequently Asked Questions

No—read it as a property.
No.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful