Strong Typing and Basic Types
Discover the distinction between strong typing in JavaScript and TypeScript and how TypeScript enforces rules for accurately using variables, functions, and objects.
We'll cover the following
JavaScript is not strongly typed. It is a language that is very dynamic, as it allows objects to change their types, properties, and behavior on the fly. TypeScript, however, is strongly typed and, as such, will enforce rules that govern how we use variables, functions, and objects.
We will start with the concepts of strong typing or static typing, as it is also known. We will then move on to exploring some of the basic types that the language uses and how the language can detect what type a variable is based on how and where it is used within our code. We will then tackle the basics of function signatures and finally see how to import and use third-party JavaScript libraries.
Strong typing
Strong typing means that when we create a variable or define a parameter in a function, we specify what type it is. Once this type has been specified, we cannot change it. Loose typing is the exact opposite of this concept, and JavaScript is a loosely typed language.
As an example of loose typing in JavaScript, let’s take a look at the following code:
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy