2.4 Dynamic Typing

Hello everyone and welcome to this course where we'll look at dynamic typing in JavaScript. One thing that separates JavaScript from many other programming languages is that JavaScript is a dynamic language. What do we mean by dynamic? Well, we have two types of programming languages. Static languages or dynamic languages. In static languages when we declare a variable the type of the variable is defined and can not be changed in the future. In a dynamic language like JavaScript, the type of a variable can change at the time of exection. Let's see this in the code. So, in the example in the last video we declared a variable "name" and we set it to a string so the type of this variable is a "string". But it may change in the future. Let's take a look at the console. So here we can run some javascript code so we're going to do a "typeof". Type of operator. And with that, we can check the type of a variable so after that we're going to add the name of the variable "name". And now we're told that it's a "string". Now if we reassign this same "name" variable to a different value. We'll assign it a value of 1. And then we check its type. It is now changed to "number". This is what we call. This is what we call a dynamic language. Unlike static language, the type of these variables will be determined at runtime according to the values we have assigned to them. Now let's see some more examples of the type of operators and by the way note that "typeof" is another reserved keyword so we can't have a variable called "typeof". Now we will clear the console with the command ctrl + L. Now let's look at the typeof We are told that it is a "number". Now if we change the age to a number with a decimal point. the type is still a number. In javascript we don't have two types of numbers, we don't have decimal numbers and integers. All numbers are of type "number". Let's look at the "isApproved" type. It is a "boolean". The type of "firstName". The type of "firstName" is not defined, the value of this variable is not defined but its type is not defined either. What does it mean ? Well rather in the previous video I told you that we have two categories of types, primitive types and reference types and in fact a but type as well. Now what about the "colorselect" type. We're going to do a "typeof". We are told that it is an object What is an object...that's the topic of our next video.