Data Types in Javascript

nameismani

Manikandan K

Posted on June 6, 2022

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
💖 💪 🙅 🚩
nameismani
Manikandan K

Posted on June 6, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How JavaScript works
javascript How JavaScript works

November 8, 2024

A Beginner's Guide to JavaScript Closures
javascript A Beginner's Guide to JavaScript Closures

November 5, 2024

Type Coercion in JavaScript Explained
javascript Type Coercion in JavaScript Explained

November 18, 2024

Introduction to Asynchronous JavaScript
javascript Introduction to Asynchronous JavaScript

October 14, 2024

Strings -- Manipulating the Immutable.
javascript Strings -- Manipulating the Immutable.

November 15, 2024