There’s A Right Way To Talk About JavaScript data Types

Juned Ahmed
4 min readJun 6, 2021

Data types basically specify what kind of data can be stored and manipulated within a program.

There are nine basic data types in JavaScript which can be divided into two main categories: there are primitive (or primary) data types and Non-primitive data types.

Primitive data types can hold only one value at a time, whereas Non-primitive data types can hold collections of values and more complex entities. Let’s discuss each one of them in detail.

Primitive data types: Undefined​, Null​, String, Number, Boolean , Symbols​ and BigInts​ are primitive data types.

  1. String Data Type: The string data type is used to represent textual data (example: sequences of characters). Strings are created using single or double quotes surrounding one or more characters, as shown below: Example:

We can include quotes inside the string as long as they don’t match the enclosing quotes.

2. Number Data Type: Number data type is used to represent positive or negative numbers with or without decimal place, or numbers written using exponential notation. Example:

The Number data type also includes some special values which are: Infinity, -Infinity and NaN. Infinity represents the mathematical Infinity , which is greater than any number. Infinity is the result of dividing a nonzero number by 0 example:

While NaN represents a special Not-a-Number value. It is a result of an invalid or an undefined mathematical operation, like taking the square root of -1 or dividing 0 by 0, etc.

3. Boolean Data Type: The Boolean data type can hold only two values: true or false. It is typically used to store values like yes (true) or no (false), on (true) or off (false), example:

4. Undefined Data Type: Undefined data type can only have one value-the special value undefined. If a variable has been declared, but has not been assigned a value, has the value undefined. Example:

5. Null Data Type: This is another special data type that can have only one value-the null value. A null value means that there is no value. It is not equivalent to an empty string (“”) or 0, it is simply nothing. Example:

6. Symbol Data type: The data type Symbol can be referred to as a “Symbol value”. In a JavaScript runtime environment, a symbol value is created by invoking the function Symbol, which dynamically produces an anonymous, unique value. A symbol may be used as an object property. example:

7. BigInts​ Data Type: BigInts​ is a numeric data type that can represent integers in the arbitrary precision format. In other programming languages different numeric types can exist, for examples: Integers, Floats, Doubles, or Bignums.

Non-primitive data types: Object, Array, and Function (which are all types of objects) are composite data types.

  1. Object Data Type: Object Data Type is a complex data type that allows you to store collections of data.

An object contains properties, defined as a key-value pair. A property key (name) is always a string, but the value can be any data type, like strings, numbers, booleans, or complex data types like arrays, function and other objects. example:

2. Array Data Type: An array is a type of object used for storing multiple values in single variable. Each value (also called an element) in an array has a numeric position.

The simplest way to create an array is by specifying the array elements as a comma-separated list enclosed by square brackets, as shown in the example below:

3. Function Data Type: Function is callable object that executes a block of code. Since functions are objects, so it is possible to assign them to variables, as shown in the example below:

Thank you so much!

--

--

Juned Ahmed

I enjoy developing applications using modern technologies. Proficient in JavaScript, Reactjs, Nodejs, Expressjs and MongoDB. Passionate about new technologies.