Data Types Javascript

There are two types of data types

Primitive types

String – It represents a series of characters and is written with quotes. A string can be represented using a single or a double quote.

Number – It represents a number and can be written with or without decimals.

BigInt – This data type is used to store numbers which are above the limitation of the Number data type. It can store large integers and is represented by adding “n” to an integer literal.

Boolean – It represents a logical entity and can have only two values : true or false. Booleans are generally used for conditional testing.

Undefined – When a variable is declared but not assigned, it has the value of undefined and it’s type is also undefined.

Null – It represents a non-existent or a invalid value.

Symbol – It is a new data type introduced in the ES6 version of javascript. It is used to store an anonymous and unique value.

To know the type of a JavaScript variable, we can use the typeof operator.

typeof “PHPCodez” // Returns “string”
typeof 7.14 // Returns “number”
typeof true // Returns “boolean”

Non-primitive types

Primitive data types can store only a single value. To store multiple and complex values, non-primitive data types are used.

Object – Used to store collection of data.

Leave a Reply

Your email address will not be published. Required fields are marked *