10+ Types of Data in JavaScript

1. Number

Number includes both integers and floats. In JavaScript you don’t need to initialize number variables using int keyword for integers and float / double keyword for floats like in C or other languages. Just initialize with var / let / const and JavaScript will automatically do the calculations for you.

The largest value a Number can hold is about 1.8×10308. Numbers beyond that are replaced with the special Number constant Infinity.

A Number only keeps about 17 decimal places of precision;

You can declare numbers of other base with 0b(Binary), 0o(Octal) and 0x(Hexadecimal) in the beginning.

Or you can convert a string to number using parseInt() .

2. BigInt

BigInt is a built-in object whose constructor returns a bigint primitive — also called a BigInt value, or sometimes just a BigInt — to represent whole numbers larger than 2²⁵³ — 1 (Number.MAX_SAFE_INTEGER). BigInt values can be used for arbitrarily large integers for Mathematical or other large calculations.

3. NaN

NaN means not a number. There are five different types of operations that return NaN:

· If you try to parse something that cannot be parsed into integers.

· Mathematical operations where the result is not a real number

· Operand of an argument is NaN

· Indeterminate forms

· Any operation that involves a string and is not an addition operation

4. String

Strings are plain text data. You can declare a string in 4 different ways:

Methods like charAt(), substring(), slice() etc can be used on strings.

5. Boolean

A JavaScript Boolean represents one of two values: true or false.

False, 0, “”, undefined, null etc are considered false. Anything that is not false is true.

6. Object

JavaScript objects can be thought of as simple collections of name-value pairs. As such, they are similar to:

· Dictionaries in Python.

· Hashes in Perl and Ruby.

· Hash tables in C and C++.

· HashMaps in Java.

· Associative arrays in PHP.

Functions and arrays are objects too in JS. Also there are some build in objects like Date.

7. Function

To declare a function, use the function keyword.

But not always! You can declare functions in JS without the function keyword too.

These are called arrow functions. There are other ways to declare a function too.

8. Array

9. Date

JavaScript Date objects represent a single moment in time in a platform-independent format.

JS Date object is interesting. It contains a Number that represents milliseconds since 1 January 1970 UTC.

New Date().getTime() will return something like 1620284104169 which means 1620284104169 milliseconds has passed from January 1, 1970.

10. RegExp

RegExp means regular expression. Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects.

11. null

The value null represents the intentional absence of any object value.

12. undefined

The variables that are declared but not assigned any value is undefined.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store