Reputation: 955
I know it would be a blasphemy for a lot of programmers if I would claim that functions are datatypes.
However if you think about it, don't you think functions are analogues to datatypes in JS. Functions are first class citizens in JS. Is that not equivalent to functions being analogous to a datatype theoretically?
Upvotes: 1
Views: 53
Reputation: 2787
Accordingly to MDN, functions are:
In JavaScript, functions are first-class objects, i.e. they are objects and can be manipulated and passed around just like any other object. Specifically, they are Function objects.
and
Functions are one of the fundamental building blocks in JavaScript. A function is a JavaScript procedure—a set of statements that performs a task or calculates a value. To use a function, you must define it somewhere in the scope from which you wish to call it.
while data types are
Six data types that are primitives: Boolean Null Undefined Number String Symbol (new in ECMAScript 6) and Object
You can also check DevDocs to see more about functions and how they are Objects. And reading this Professional JS would make your opinions clearer. Javascript Garden offers better understanding of the function as a first-class
object.
Object is a basic JavaScript Data type, and the Function Object is one of its types. So, the answer is no, it would not be right to call a JS function a data type.
Upvotes: 4
Reputation: 8661
That's just a description choice, really.
Functions and arrays add something specific to the general definition of the basic "object" data type, and a large portion of the language deals with their specificities.
Still for some reason ECMA does not call them data types.
They're the bosses there.
Upvotes: 1