JavaScript Data Types

JavaScript Data Types:

There are many data types in JavaScript: numbers, strings, objects and more:

The String Data Type:

The string data type is used to represent textual data (sequences of characters). Using single or double quotes surrounding one or more characters Strings are created, as shown below:
Example:
var x = 'Hello Tutorials!';  // using single quotes 
var y = "Hello Tutorials!";  // using double quotes
You can also include quotes inside the string but be careful that they don't match the enclosing quotes.
Example:
var x = "It's a holiday."; // using single quote inside double quotes 
var y = 'It is a "holiday" .';  // using double quotes inside single quotes 
var z = 'I\'ll go home.';     // using escaping single quote with backslash

The Number Data Type:

To represent positive or negative numbers with or without decimal place we use number data type.

Example:
var x = 11;         // using integer number
var y = 11.5;       // using floating-point number 

The Boolean Data Type:

The Boolean data type can hold only two values: true or false.
Example:
var x = true;   // using true value 
var y = false; // using false value 

The Undefined Data Type:

The undefined data type have one value that is "undefined". If a variable is declared, but this variable has not assigned a value, then this variable has the value "undefined".

Example:
var x; 
var y = "hello bangla tutorials point!" 
alert(x) // result: undefined 
alert(y) // result: hello bangla tutorials point!

The Null Data Type:

This Null data type have only one value that is null value. null value means there is no value. It is not equivalent to an empty string ("") or 0. it is simply nothing.
Example:
var x = null; 
alert(x); // result: null 
var y = "hello bangla tutorials point!" 
alert(y); // result: hello bangla tutorials point
y = null; 
alert(b) // result: null

The Array Data Type:

An array is special variable that is used to store multiple values in single variable. Each value is also called an element in an array has a numeric position, known as its index Number. Index number start with 0.

Example:
var university = ["Iubat", "BUET", "DUET", "DU"]; 
var Town = ["Dhaka", "Mymensingh", "Comilla"]; 
alert(university[0]);   // result: Iubat
alert(Town[2]);   // resultComilla
In the video I have described all JavaScript Data Types.


EmoticonEmoticon