Back to all questions

What data types are there in JavaScript?

Devs Hive

Devs Hive

Seen on interview: 5 users

This question often stumps even senior developers, although it is actually very simple.

When you hear it, there's no need to overcomplicate things with answers like: there are arrays, objects, functions… - because from the data type perspective in JavaScript, all of these belong to a single non-primitive type - object.

Non-primitive type: object

Almost everything "complex" belongs to object:

  1. { a: 1 } - an object
  2. [1, 2, 3] - an array (but the type is still object)
  3. new Date() - a date (also an object)
  4. function () {} - a function (technically it is an object, but typeof returns function for it)

Primitive types (there are 7)

Besides object, JavaScript has 7 primitive types - they are not objects and don't have methods/properties like контейнери (although JS sometimes wraps them in wrapper objects under the hood).

  1. string - strings: hello
  2. number - numbers: 42, 3.14, NaN, Infinity
  3. boolean - boolean type: true / false
  4. null - empty value (an explicitly assigned absence of value)
  5. undefined - value not assigned
  6. symbol - unique identifiers: Symbol(id)
  7. bigint - large integers: 123n

In total: 7 primitives + 1 non-primitive type, object. You can read about the difference between null and undefined at https://devs-hive.tech/interview-qa/null-vs-undefined-js.

Seen on interview?

Comments (0)

Sign in to leave a comment

No comments yet. Be the first!