Datatypes in JavaScript

In programming, data types is an important concept. To be able to operate on variables, it is important to know something about the type. Every variable has a datatype that indicates what kind of data the variable holds. There are five basic data types in JavaScript :

1. Number :

The number datatype represents the numeric values. Example :
  var num = 300;
Number datatype indicates both integer and floating-point, means it can be written with, or without decimals.
var num1 = 24.67, num2 = 300.67;

2. Strings :

The string datatype represents sequence of characters. Strings are written with quotes, either single or double quotes. There is no meaning difference for the type of quotes and they are inter-changeable. Example :
  var str1 = "Hello world.";
  var str2 = 'Hello world Again.';

3. Boolean :

The boolean datatypes can have two values true or false, which is used both as variable values and within loops and conditions as a literal. Example:
  var bool1 = true;
  var bool2 = false;
Boolean type is use to perform logically operator to determine condition/expression is true.

4. Null :

The Null datatype define the null value or no value at all. It indicates the absence of data. It indicates the absence of data. For example, when placed in an unspecified function argument.
  var dat = null; 

5. undefined :

The undefined datatype represents undefined values. In JavaScript, the uninitialized variables consists the value undefined. In context of boolean values the uninitialized variables return false.


Non-Primitive data types :

Apart from primitive datatypes, in JavaScript there are also non-primitive data types. Which are as follows :

1. Object : 

The object data type represents instance through which we can access members. JavaScript objects are written with curly braces. Object properties are written as name:value pairs, separated by commas. Example :
  var details = {firstName:"Jack", lastName:"Ritcher", age:41};

2. Array :

The Array represents group of similar values. JavaScript arrays are written with square brackets and array items are separated by commas. Example :
  var code = ["C", "Java", "Python", "HTML", "CSS", "JavaScript"];

3. RegExp or Regular Expression :

A regular expression is a sequence of characters that forms a search pattern. The search pattern can be used for text search and text replace operations.


Next Topic :