DEV Community

Cover image for Data Types in Javascript
Manikandan K
Manikandan K

Posted on

Data Types in Javascript

DATA TYPE

Data type is, in a programming language, a classification that specifies what type of value, that variables hold/store.

In js have seven primitive data types and one non-primitive data type.

Primitive type

In js primitive type represents data that is not an Object and that has no methods or properties.

String :
In JavaScript String is used to store text. String wrap by quotes.

Example: 
const name1 = 'Manikandan";
const name2 = "Manikandan";
const name3 = `Manikandan`;
Enter fullscreen mode Exit fullscreen mode

Number :
Number represents integer and floating-point numbers(decimal numbers).

Example: 
const number = 10;
const number = 20.25;
Enter fullscreen mode Exit fullscreen mode

Boolean :
Boolean represents logical entities that true and false.

Example:
const isFetch = true;
const isChecked = false;
Enter fullscreen mode Exit fullscreen mode

Undefined :
The Undefined data type represents, the variable is declared. But value is not initialized.

Example: 
let a;
console.log(a);  // Undefined
Enter fullscreen mode Exit fullscreen mode

Null :
The null data type represents an empty or unknown value.

Example:
const number = null;
Enter fullscreen mode Exit fullscreen mode

symbol :
Data type whose instances are unique and immutable.

BigInt :
Its represents integer with arbitrary precision.

Example: 
900719925124740999n
Enter fullscreen mode Exit fullscreen mode

Object :
An object is a non-primitive data type in JavaScript.
In js Object is used to store the collection of Data.

Example:
const person = {
    firstName: 'Manikandan';
    lastName: 'MK';
    age: 24;
    isEmployee: true;
}
Enter fullscreen mode Exit fullscreen mode

JavaScript typeof :
To find the type of variable, we can use typeof operator.

Example:
const name = 'Manikandan'
console.log(typeof(name));  // return string;

const id = 1010;
console.log(typeof(id));  // return number;

const isChecked = true;
console.log(typeof(isChecked));  // return boolean;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)