DEV Community

Cover image for Data Types in Javascript
Manikandan K
Manikandan K

Posted on

3 1

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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay