top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What datatypes are supported in Javascript?

+2 votes
288 views
What datatypes are supported in Javascript?
posted Feb 24, 2014 by Merry

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote
 
Best answer

There are
- Numbers
- Strings
- Booleans
- Objects
- null
- undefined

Note that there isn't a separate Integer, just number - which is represented as a double precision floating point number.

There's also
- Functions
- Arrays
- RegExps

all of which are Objects deep down, but with enough special wiring to be mentioned on their own.

Credit: Stackoverflow

answer Feb 25, 2014 by Sanketi Garg
+2 votes

JavaScript has dynamic types. This means that the same variable can be used as different types:

var x;               // Now x is undefined
var x = 5;           // Now x is a Number
var x = "John";      // Now x is a String
var x = true;        // Now x is a Boolean 

However Javascript Array and Object does not apply to the above rule which are descried blow.

Arrays

var cars=new Array();
cars[0]="BMW";
cars[1]="Merc";
or 
var cars=new Array("BMW","Merc");

Objects

var person={firstname:"Salil", lastname:"Agrawal"};
answer Feb 25, 2014 by Salil Agrawal
...