2

Function and Object are special types of a function, since having a capital letter starting, they are constructor-functions, right?

Functions as 1st class citizens in JavaScript can have methods (functions that are stored as properties in an object), as well.

So functions are objects, right? The constructor-function Function's property prototype has typeof "function" whereas the constructor-function Object's property prototype has typeof "object".

Why isn't it "object" both times?

typeof Function.prototype
>"function"

typeof Object.prototype
>"object"

Function.prototype
> ƒ () { [native code] }

Object.prototype
> {…}
quizmaster987
  • 549
  • 1
  • 6
  • 15
  • 1
    https://www.ecma-international.org/ecma-262/5.1/#sec-11.4.3 – Keith May 21 '20 at 08:54
  • Interesting. I never realised that ;) Please note that these are not special functions other than being native functions. The capital-letter-constructor thing is just convention. Some can be used as constructor only, other can be used to coerce into a different type (e.g. `Number("42") //=> 42`). Other are just "namespace", e.g. you can't invoke `Math`) – customcommander May 21 '20 at 10:13
  • Do I have to delete that question, since it is duplicate? Or is that done automatically? – quizmaster987 May 22 '20 at 06:45

0 Answers0