You've probably met typeof operator in the past. In the Accounting module of Watch and Code Premium, typeof is used to check if a value is 'function', 'number', or 'undefined'. Based on this, one could conclude that these are JavaScript types, but this isn't the case. The goal of this writeup is to explain why typeof doesn't report true JavaScript data types and spare others of frustration.


The way JavaScript should work is specified by a group of technical experts from an international body called Ecma International. They produce authoritative detailed technical instructions on how JavaScript code should be interpreted by the computer. Every year this group expands the JavaScript language, making it more powerful by adding new features. The first in this series of annual improvements was in 2015, nicknamed ES6, which introduced Symbol. The set of improvements from 2019 introduced the newest data type called BigInt. According to the ECMA specification, there are currently 8 data types in JavaScript:

Primitive data types
Undefined
Null
Boolean
String
Number
Symbol
BigInt
Complex data type
Object

So what's up with typeof function () {} === 'function' when 'function' can't be found among the list of data types? It turns out that typeof has multiple bugs that were never fixed in order to ensure backward compatibility. Technically, a function in JavaScript is of type Object and in my opinion typeof should report it as such. Unfortunately, typeof function () {} === 'function' is just one of many backward compatibility issues we're stuck with.