Type Hinting in JavaScript

Most developers understand that JavaScript does not have a notion of datatypes: it’s often referred to as “dynamically typed”,  “weakly typed,” or even “untyped.”  The distinction is mostly academic, and the bottom line is when you declare a variable, you don’t specify its datatype.  For example, if you see this:

There’s no way to know whether animals is an array, a string, a function, or something else.  So how do you make sure that people use variables as they were intended?

The first and most obvious solution is to document all your types.   If your program fits in one or two files, you can just check the documentation to determine any given type. But when your application spans dozens or hundreds of files, or the number of developers working on it begins to climb, this solution can quickly lead to a huge mess. When you get to this point, it’s helpful to offload “checking that function signature” to your IDE or text editor.
Read more