JavaScript Data Types


JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript.

  • Primitive data type
  • Non-primitive (reference) data type

JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type. It can hold any type of values such as numbers, strings etc.

var a=18;//holding number
var b="Sachin";//holding string

JavaScript primitive data types

There are five types of primitive data types in JavaScript.

Data TypeDescription
StringA string (or a text string) is a series of characters e.g. "Hello"
Numberrepresents numeric values e.g. 100
BooleanBooleans can only have two values: true or false.
Undefinedrepresents undefined value
Nullrepresents null i.e. no value at all

JavaScript Strings

A string (or a text string) is a series of characters.

Strings are written with single or double quotes:

var Name = "Acer";   // Using double quotes
var Name = 'Dell';   // Using single quotes

You can use quotes inside a string.

var answer = "Hello World";       // Single quote inside double quotes
var answer = "Hello 'World'";    // Single quotes inside double quotes
var answer = 'Hello "World"';    // Double quotes inside single quotes

JavaScript Numbers

Represents numeric values e.g. 100

var x1 = 12.00;     // Written with decimals
var x2 = 67;        // Written without decimals

Extra large or extra small numbers can be written with scientific (exponential) notation:

var y = 235e6;      // 235000000
var z = 235e-6;     // 0.000235

JavaScript Booleans

Booleans can only have two values: true or false.

Booleans are often used in conditional testing.

var a = true;
var b = false;

JavaScript non-primitive data types

The non-primitive data types are as follows:

Data TypeDescription
Objectrepresents instance through which we can access members
Arrayrepresents group of similar values
RegExprepresents regular expression

JavaScript Objects

JavaScript objects are written with curly braces.

Object properties are written as name:value pairs, separated by commas.

var studentinfo = {Student Name:"Sachin", Section:"Jk201", Reg No:11211855, Year:3rd};

JavaScript Arrays

JavaScript arrays are written with square brackets.

Array items are separated by commas.

var name = ["Ashwani", "Sachin", "Deeepak"];

Share this article on