โš–๏ธcallable vs. constructable

  • if a function can be invoked in the form F(), it's callable.

  • if a function can be invoked in the form new F(), it's constructable.

not every function is callable, for example, Map is a function, but calling it with Map() throws a TypeErrorโ—

not every function is constructable, for example, Symbol is a function, but calling it with new Symbol() throws a TypeErrorโ—

function
F()
new F()
note

Array, Error, Function

โœ…

โœ…

same effect

Boolean, String, Number

primitive

wrapper object

Date

string

object

Symbol, BigInt

โœ…

โ›”๏ธ TypeError

Proxy, Map

โ›”๏ธ TypeError

โœ…

class

โ›”๏ธ TypeError

โœ…

Last updated