JS ⟩ value ⟩ object ⟩ create ⟩ new ⟩ callable vs. constructable
if a function can be invoked in the form F(), it's callable.
F()
if a function can be invoked in the form new F(), it's constructable.
new F()
not every function is callable, for example, Map is a function, but calling it with Map() throws a TypeError❗
Map()
not every function is constructable, for example, Symbol is a function, but calling it with new Symbol() throws a TypeError❗
new Symbol()
👉 [[Call]], [[Construct]] internal methods.
constructor is a constructable function.
replit ⟩ callable vs. constructable
// Array is callable & constructable, same effect. let arr1 = Array(3); let arr2 = new Array(3); let map = Map(); // Map is not callable. // ^^^ // ⛔ TypeError: Constructor `Map` requires 'new' let sym = new Symbol(); // Symbol is not constructable. // ^^^ // ⛔ TypeError: `Symbol` is not a constructor arr1, // [ , , ] (3 empthy items) arr2, // [ , , ] (3 empthy items) Map instanceof Function, // true Symbol instanceof Function, // true
JS.info ⟩ Constructor, operator "new"
new operator ⭐️
Array, Error, Function
✅
same effect
Boolean, String, Number
primitive
wrapper object
Date
string
object
Symbol, BigInt
⛔️ TypeError
Proxy, Map
class
Last updated 2 years ago