Set.prototype.has() — JS Technical Interview Questions & Answers
Checks whether a value exists in the Set.
Set.prototype.has()
- Set.prototype.has() 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.has().
- From the example next to this theory: Checks whether a value exists 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.has()? Then show class Student { constructor(name) {} }. Then name the trap.
Technical Interview Tip: What is Set.prototype.has()? Show this: class Student { constructor(name) {} }. Trap: arrow function for a method that needs this.
Code Examples for Set.prototype.has()
Set.prototype.has() — working example
const tags = new Set(["js", "js", "sql"]);
tags.add("css");
console.log(tags.has("js"), tags.size);
console.log([...tags]);Set.prototype.has() — set stores unique values — great for dedupe and membership checks.
How to Explain Set.prototype.has() to an Interviewer
What is Set.prototype.has()?
Used for class Student a tiny OOP file Not just the heading
Give one small example of Set.prototype.has().
class Student { constructor(name) {} } Checks whether a value exists in the Set
What mistake do beginners make with Set.prototype.has()?
arrow function for a method that needs this Show the fix
Where do you use Set.prototype.has()?
a tiny OOP file class Student