Variables In JavaScript

In Javascript, several data types are supported such as Boolean, Number, String, Object, Null, and Undefined. However, all data types, no matter what they are, are declared with the help of a common keyword called "var". Data types in JavaScript may be of the type primitive or object.
The following are the primitive data types that are supported in JavaScript,
  1. Boolean = It represents a logical value of an object or a statement, and can assume the value of "true" or "false".
  2. Null = Null represents the absence of any value to a given object. It indicates that the variable points to no object.
  3. Undefined = A variable whose value hasn't been assigned yet is called is undefined. A statement returns undefined if the variable which is being talked about in the statement has not been assigned a value. A function returns undefined if no value is returned by the function.
  4. String = A collection of alphabets or characters is called a string.
  5. Number = A number in Javascript can be declared also using just the "var" keyword, irrespective of whether the number is an integer, float, negative number, or decimal. This is unlike many other programming languages where we require different keywords for different kinds of numbers.
Let's discuss the Undefined and Null data type.
The difference between Undefined and Null data type,
  1. A variable that has been declared but not yet assigned a value to it has a data type of “undefined”.
  2. On the other hand, Null is an assignment value. The null value represents an empty or non-existent reference value.
Here an example,
  1. var address = null;   
In the above statement, a variable has an explicit value.
another way of creating a variable is,
  1. var address;   
Now, the above variable would have a type undefined.
Apart from the primitive, we also have a data type called Object in Javascript. Let's discuss the object.
An object is a collection of properties. You can imagine a JavaScript object to be a kind of a hashmap wherein each property is stored in the form of a key/value pair. These properties may in themselves consist of any kind of data type, primitive, or an object within an object.