Managing dynamic typing
Data types are one of the basic features that ensure consistency throughout an application. Some operations can be made only on specific data types and checking if a value is of a valid data type is crucial to avoid runtime exceptions. Most compiled Object-Oriented Programming languages have a static type system that asks the developer to declare the allowed type of a variable and check the code before it runs. JavaScript is a dynamic language—it does not require you to declare a specific data type for a variable. Since the content of a variable can change during the execution, data type checking of its value is performed just when the value itself is used. Let's recall some basic notions with some examples.
Dynamic data types
We know that a variable does not have an associated type declaration in JavaScript. It can contain any value and its type depends on its content. This does not mean that JavaScript does not support data types. It just means that...