Set.prototype.size — JS Technical Interview Questions & Answers

The number of unique values in the Set.

Set.prototype.size

  • Set.prototype.size is a JS topic. In plain words you use it for class Student in a tiny OOP file. Don’t start with a slogan — start with that picture.
  • Smallest example: class Student { constructor(name) {} }. Type it, run it, and say what you see. If you can do that from memory, you know Set.prototype.size.
  • From the example next to this theory: The number of unique values in the Set.
  • Trap: arrow function for a method that needs this. Fix that before you talk about advanced JS.
  • Viva: what is Set.prototype.size? Then show class Student { constructor(name) {} }. Then name the trap.

Technical Interview Tip: What is Set.prototype.size? Show this: class Student { constructor(name) {} }. Trap: arrow function for a method that needs this.

Code Examples for Set.prototype.size

Set.prototype.size — working example

const tags = new Set(["js", "js", "sql"]);
tags.add("css");
console.log(tags.has("js"), tags.size);
console.log([...tags]);

Set.prototype.size — set stores unique values — great for dedupe and membership checks.

How to Explain Set.prototype.size to an Interviewer

What is Set.prototype.size?

Used for class Student a tiny OOP file Not just the heading

Give one small example of Set.prototype.size.

class Student { constructor(name) {} } The number of unique values in the Set

What mistake do beginners make with Set.prototype.size?

arrow function for a method that needs this Show the fix

Where do you use Set.prototype.size?

a tiny OOP file class Student