JavaScript #5 – Data Types and Data Structures

JavaScript as a programming language has many built-in, different types of data and structures that can store information. What is different from the other languages, JavaScript has dynamic types of data. This means that the same variable can be used to hold different data types. Also, when you are using variables, they can be easily transformed into another type.

Data can be one of six types of information (primitives)

they can be also, object

You need to know, that JavaScript nowaday supports three keywords to declare information. In above example I use var, that is an abbreviation of the variable. You should use this keyword to make global variables. In comparison to let, they are visible also over block scope, where they are declared.

the output of above code was 3 and 2. Why? Because brackets create block scope. And as I mention in the previous paragraph, let declares a local variable, and var has global range. So, you declared a global variable with value 1, in block variable is assigned to the new value (3). And after that scope, you get 3 as result. From the other hand, we have local variable b. They are declared in global scope, so inside of block scope is created the new instance of this variable with other value. Outside this block, you have still 2.

The third keyword that, you can use to declare is const (constant). It’s very similarly to let but, when you once declare, you cannot change a value.

 

Herbaciarz

 

Leave a Reply

Your email address will not be published. Required fields are marked *