Since both String{}
and String()
gets the same name, why console.log(String)
choose the function instead the object?
For obvious reasons: String
is a function and String.prototype
is an object. It would be rather confusing if Chrome would generate the same output for those two different values/data types.
For functions, Chrome actually shows the implementation of the function (func.toString()
). Some functions are not implemented in JavaScript but in native code and hence you see [native code]
instead.
For objects, Chrome takes the name of the function (if available) referred to by the constructor
property of the object. The value of String.prototype.constructor
is String
.