Data Types in Javascript
Manikandan K
Posted on June 6, 2022
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`;
Number :
Number represents integer and floating-point numbers(decimal numbers).
Example:
const number = 10;
const number = 20.25;
Boolean :
Boolean represents logical entities that true and false.
Example:
const isFetch = true;
const isChecked = false;
Undefined :
The Undefined data type represents, the variable is declared. But value is not initialized.
Example:
let a;
console.log(a); // Undefined
Null :
The null data type represents an empty or unknown value.
Example:
const number = null;
symbol :
Data type whose instances are unique and immutable.
BigInt :
Its represents integer with arbitrary precision.
Example:
900719925124740999n
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;
}
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;
Posted on June 6, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.