In Chapter 3, Nitty-Gritty Grammar, we discussed using typeof() to ascertain what a variable's data type is and using let and const to define them. There's an interesting fact about JavaScript that Python shares: both are dynamically typed. As opposed to statically typed languages such as Java, JavaScript's variable types can change over the course of a program. This is one reason why typeof() can come in handy.
Let's take a look at a quick example contrasting JavaScript with Java:
Java | JavaScript |
int age; |
let age |
If we tried to run the Java code, we'd get an error stating that the types are incompatible. In Java, variables have a type. When we run the JavaScript code, however, everything's just fine. In JavaScript, values have a type.
It's also important to know that JavaScript is weakly typed...