Datatypes in JavaScript for beginners

Datatypes in JavaScript for beginners

There are 2 types of data types in javascript.

  1. Primitive datatype.

  2. Reference datatype.

Let's talk about primitive datatypes first.

The predefined data types provided by JavaScript language are known as primitive data types. Primitive data types are also known as in-built data types.

The main features of a primitive data type are:

  1. It is not an object (a collection of keys and values)

  2. It does not have its methods (property of an object which is a function)

  3. It is immutable (it cannot be changed and is read-only).

Primitive datatypes:

  1. Number.

  2. String.

  3. Boolean.

  4. Undefined.

  5. Null.

  6. Array.

  7. Symbol.

Number:

Any magnitude of numbers can be stored using number datatype in javascript.

String:

A string is a sequence of characters or it can be a single character that represents text. A string can be created using single or double quotes.

Boolean:

The boolean data type has only two values, true and false. In some places when we check a condition or the existence of a variable or a value, true and false implies a ‘yes’ for ‘true’ and a ‘no’ for ‘false.

Undefined:

If the variable is not defined with any value then the type and value of that variable will be considered an undefined type.

Null:

If a variable is defined with a null value then the value of that variable will be null and the type will be an object.

Array:

An array is a collection of multiple items. You can store different types in an array.

Symbol:

The JavaScript ES6 introduced a new primitive data type called a symbol. Symbols are immutable (cannot be changed) and are unique. Though the value of a and value of b both contain the same description, they are different.

Did you find this article valuable?

Support Sandip Halder by becoming a sponsor. Any amount is appreciated!