JavaScript – Data Types

What is a Data type ?

Data type is an attribute that a data value can have.

Its defines the type of value that a data can hold in a programming language.

It also tells the characteristics (predefined attribute) of the data value to the compiler for the variables.

What is the data type in JavaScript ?

In Javascript, data type is defined as the type of values that a variable can hold.

Mostly in Javascript, all the variables are declared using the var keyword.

This var keyword can hold any type of values such as numbers, strings etc.

Example :

var a = "Abdul";
var b = 10;

It can hold String and also Numbers.

How to specify the data type of a variable in Javascript ?

In general, JavaScript is a dynamic programming language.

In Javascript, we do not need to specify the data type of the variable.

The data type of the variable is assigned dynamically by the Javascript engine.

Just by declaring a variable with var keyword , the data type is assigned dynamically.

Javascript online learning !!!

Click to Learn More about – Javascript online learning

What are the types of data types in JavaScript ?

There are two types of data types in Javascript, they are

1. Primitive Data type.

2. Non-Primitive Data type.

1. Primitive Data Type :

Primitive data types are the most basic data types in Javascript.

It is defined by the programming language.

Primitive data types is further classified into five types.

1. String

String data-type represents sequence of characters enclosed within double codes.

	var name = "AbdulKalaam";

2. Number

Number data-type represents numeric values.

var a = 10;

3. Boolean

Boolean data-type represents boolean value either true/false.

	var a = true;

4. Undefined

Undefined data-type represents undefined value for variable.

	var a;
	alert(a); // a is Undefined

5. Null

Null data-type represents the null value for a variable.

	var a = null;

2. Non-Primitive Data type.

Non-primitive data types are created by the programmer/developer.

Reference variables/Objects are Non-Primitive data type, since they refer a memory location, where data is stored.

Non-Primitive data types is further classified in to three types.

1. Object

Object data-type represents the instance through which we can access object members.

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

Objects are written with curly braces {}.

	var a = {FirstName:"Abdul",LastName:"Kalaam", Age:83};

2. Array

Array is the group of similar values.

Array items are separated by commas.

Arrays are written with square brackets.

	var a = ["Abdul","Kalaam","83"];

3. RegExp

RegExp represents regular expression.

	var regularExp = /ab+c/;


	var regularExp = new RegExp('ab+c');