JavaScript Data Types

JavaScript includes data types similar to other programming languages like Java or C#. Data type indicates characteristics of data. It tells the compiler whether the data value is numeric, alphabetic, date etc., so that it can perform the appropriate operation.

JavaScript includes primitive and non-primitive data types as per latest ECMAScript 5.1.

Primitive Data Types

  1. String
  2. Number
  3. Boolean
  4. Null
  5. Undefined

Non-primitive Data Type

  1. Object
  2. Date
  3. Array

JavaScript is a dynamic or loosely-typed language because a variable can hold value of any data type at any point of time.

Example: Loosely-typed JavaScript
var myVar = 100;
myVar = true;
myVar = null;
myVar = undefined;
myVar = "Steve";

alert(myVar); // Steve

In the above example, myVar will hold last assigned value to it that is string "Steve".

Let's learn about each data type in detail in the next section.