DEV Community

Santhi Sri Jamisetty
Santhi Sri Jamisetty

Posted on

Variables and Datatypes In JavaScript-series-1b

JavaScript is loose typed which means you don't need to specify the type of variable while declaring it, which differentiates other languages like Java, C++ wherein you need to specify its type while declaring a variable.
Ex: In JavaScript var age = 10;
In Java

int age = 10; specify the type of variable.

The Primitive Type datatype includes :

1)String ex: var color = "orange";
2)Number ex: var salary = 100;
3)Boolean(to check true or false) ex: isCatSleeping = true;
4)Null ex:refer to series 1a where in the table you see the "Registration Cost " for Andy Young has no value.
5)Undefined ex: var myCar; the variable myCar declared but has not set any value.
6)BigInt(recently added). These are for micro-precision timestamps.Please refer to MDN JavaScript for further reading.

Note:To check the variable dataype use this function called typeof();
Ex: var color = "orange";
typeof(color)
output is "string".

The other called complex/composite datatypes because these include Objects as well as the Primitive types.
Objects includes Array
Array
Function etc.
We will learn about object-oriented programming later.

Modern browsers use ECMASCRIPT to overcome the scope of the variables. We will learn about it in series 1c. where we learn about hoisting, let, const etc.

Top comments (0)