JavaScript Datatype

JavaScript supports four primitive datatype and complex types as arrays and object.

Primitive data types are types that can be assigned a single literal value such as number, string or boolean value. Literals are fixed values.

Number Datatype

Number consists of integer and floating point number and the special NAN (Not a Number value).

Integer (base 10) can be represented in decimal 0 to 9.
Octal (base 8) can be represented in decimal 0 to 7.
Hexadecimal (base 10) can be represented in decimal 0 to 9 and letter A to F.

Floating point are used to represent number that requires the use of a decimal point, or very large or very small numbers that must be written using exponential notation.

Example of floating point:- 12.4, -4.2.

Boolean Datatype

Boolean cinsust of only two logical value true and false.

JavaScript automatically converts the boolen value true and false into 1 and 0. When they are used in numberical expression.

For example:- a==4

If the value of variable a is equal 4, if it is the result of this comparison is true. If a is not equal to 4, the result of the comparison is false.

String Datatype

String consists of string values that are enclsed in single or double quotes.

A string is a sequence of Zero or more charaacters that re enclosed within sing (‘) or double (“) quotes.

These characters can be letters, digital, punctuation character.

Example of string

var a="two" 

alert (a); //This will alert "two"
Plus sing (+) used with sting

var a="abc"

alert(a+a); //This will alert "abcabc"

Null Datatype

Null represents a single value, null that indicates “no values”.

Example of null

var a=null

alart(a); //This will open a dialog containing 'null'

Undefined Datatype

Simple, if we declare a variable able by giving it a name but no value, that variable contains a values of undefined.

Example of undefined

var a;
alert (a) //This will open dialog containing “undefined”

Leave a Reply