Back to questions
JuniorTheoryCommon
What does the program print?
const s = new Set([1, "1", 1, 2]);
console.log(s.size);3
- Expecting
2: aSetcompares values like===, without type conversion, so the number1and the string"1"are different values and both stay. - Expecting
4: aSetkeeps each value once, so the second1is not added again.
- What does
s.has(2)return, and what doess.has("2")return? - How would you get an array of the values without repeats from this
Set?