console.log(typeof String.prototype); // object console.log(typeof Number.prototype); // object console.log(typeof Object.prototype); // object console.log(typeof Boolean.prototype); // object console.log(typeof Function.prototype); // function
Why does typeof Function.prototype
return "function", not "object" like other prototype objects?
Thank you!
The TypeOf function is an important tool when dealing with complex code. It allows a programmer to quickly check a variable's data type—or whether it's “undefined” or “null”—without going through the code line by line! Additionally, the TypeOf function can also check whether an operand is an object or not.
Every object in JavaScript has a built-in property, which is called its prototype. The prototype is itself an object, so the prototype will have its own prototype, making what's called a prototype chain. The chain ends when we reach a prototype that has null for its own prototype.
In computer programming, a function prototype or function interface is a declaration of a function that specifies the function's name and type signature (arity, data types of parameters, and return type), but omits the function body.
prototype is a property of a Function object. It is the prototype of objects constructed by that function. __proto__ is an internal property of an object, pointing to its prototype. Current standards provide an equivalent Object.
This seems to be defined in ECMAScript 5:
15.3.4 Properties of the Function Prototype Object
The Function prototype object is itself a Function object (its
[[Class]]
is "Function") that, when invoked, accepts any arguments and returns undefined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With