Ben Aston
Ben Aston

Reputation: 55739

Is function a discrete type in JavaScript?

I can identify the following types in JavaScript:

number, string, boolean, object, null and undefined

But, is function a discrete type, or is it an instance of object?

Upvotes: 0

Views: 470

Answers (1)

G Roy
G Roy

Reputation: 166

Functions in javascript are inherited from Object. You can try the following :

var my_func = function(){};
console.log(my_func instanceof Object); // prints true
console.log(my_func instanceof Function); // also prints true

The same is true for Array.

Upvotes: 1

Related Questions