What are JavaScript Data Types?
Asked
Active
Viewed 1.9k times
30
-
2Why this question was voted down? – Kamarey Aug 17 '09 at 16:03
-
Yonita, what do you mean? Are you looking for a list of the data types offered by JavaScript, or do you want to know what the word "datatype" means? – John Saunders Aug 17 '09 at 19:22
-
I'm sure the question was voted down because it is very unclear what she's asking. – John Saunders Aug 18 '09 at 08:04
-
1Unclear? I guess it's pretty straightforward - @Ennovy is asking the data types available for JavaScript. This is a real question. – Ardee Aram Jul 08 '13 at 04:41
-
see this: http://symfony-world.blogspot.com/2013/07/javascript-datatypes.html – ducin Oct 23 '13 at 19:35
-
2This _is_ a real question. Clear and up to the point as it could possibly be. – GOTO 0 Aug 03 '15 at 08:24
-
This [JavaScript data types and data structures](https://youtu.be/AsJhjDirCUI) video might be helpful. – Mahmoud Jun 01 '20 at 21:37
-
The question is clear and proper. Please vote to reopen – Tom Smykowski Oct 31 '21 at 07:19
3 Answers
25
There's
- 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.

Magnar
- 28,550
- 8
- 60
- 65
-
-
-
-
2@Nosredna & @Magnar - Unless I'm sorely mistaken, no they aren't: `alert( typeof function(){} )` vs `alert( typeof {} )` – Peter Bailey Aug 17 '09 at 15:42
-
Keep in mind that `null` is always reported as `Object` when passed into the `typeof` function. – Dan Herbert Aug 17 '09 at 15:50
-
According to http://www.crockford.com/javascript/survey.html everything apart from numbers, strings and booleans are objects. They do behave differently enough that they might aswell be listed as a separate datatype. Fixing. – Magnar Aug 17 '09 at 15:53
-
@Peter Bailey. It depends. JavaScript is notorious poor at reflection of its types. I wouldn't go by what it _says_ its types are. – Nosredna Aug 17 '09 at 15:59
-
Arrays are Objects too.. I feel this slope is getting slippery.. should we add Dates and RegExp too now? No, they're objects. I'm about to change my mind on functions again. ;-) – Magnar Aug 17 '09 at 20:50
-
4Arrays definitely have their own place in the language. They are objects, but there's a lot of extra rigging built around them. The real answer is that with JavaScript, answers are almost always mushy. Good answers are always followed up with "yes, but" clauses. It's a very flexible language. A shapeshifter, ready to throw on a blonde wig and party dress any night of the week. – Nosredna Aug 17 '09 at 22:18
-
-
17
There are five primitive data types in JavaScript:
- number
- string
- boolean
- undefined
- null
Everything that is not a primitive is an object.

Srikar Doddi
- 15,499
- 15
- 65
- 106
-
Isn't null an empty object used to initialize object that don't have values? Why is it still considered a primitive type? -- sorry noob here – anpatel Mar 12 '15 at 15:38
2
Javascript has a typeof
operator that returns a string that names the datatype of its argument. So, you could say that the datatypes in Javascript are all the possible return values of this operator. Look here:
https://developer.mozilla.org/en/JavaScript/Reference/Operators/typeof