29

What are JavaScript Data Types?

2

3 Answers 3

24

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.

Sign up to request clarification or add additional context in comments.

11 Comments

And there are special-purpose objects like Dates.
Good point, Peter Bailey--functions are objects.
Functions are Objects in JavaScript, but yeah.
@Nosredna & @Magnar - Unless I'm sorely mistaken, no they aren't: alert( typeof function(){} ) vs alert( typeof {} )
Arrays 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.
|
17

There are five primitive data types in JavaScript:

  1. number
  2. string
  3. boolean
  4. undefined
  5. null

Everything that is not a primitive is an object.

1 Comment

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
1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.