denysdovhan / wtfjs

🤪 A list of funny and tricky JavaScript examples
http://bit.ly/wtfjavascript
Do What The F*ck You Want To Public License
34.62k stars 2.54k forks source link

Symbol is a constructor but not a constructor #255

Closed Pentadome closed 2 years ago

Pentadome commented 2 years ago
Boolean.prototype.constructor === Boolean // -> true
new Boolean() // -> Boolean {false}
Symbol.prototype.constructor === Symbol // -> true
new Symbol() // -> Uncaught TypeError: Symbol is not a constructor

Symbol is not a constructor, nevertheless, it is the value of Symbol.prototype.constructor. This is because, unlike booleans, symbols cant be explicitly boxed.