Data-Types
JavaScript is a loosely typed scripting language and over a time Javascript variables can receive different data types. A data type in a language defines the type of data variable that can hold. Data type basically typed data that can be used and manipulated in a program.
The latest ES6 standard defines the following data type: out of which 6 data types are primitive
Numbers
It represents both integers and floating-point numbers. EX- 4,6,7,4.6,94.9
let num = 2;
let count = 93.2;
String
A string is a sequence of characters. In Js, string can be enclosed within the single and double quotes. EX-
let name = Anurag;
let teacher = Hitesh;
Boolean
It represents the logical entity and can have two values true or false.
let login = true;
let Count = false;
Null
this type has one value: Null We discuss null in the next article
Undefined
A variable that has not been assigned a value is undefined.
Symbol
Introduced in ES6. Unlike other primitive data type, it does not have any literal form. It is a built-in object whose constructor returns a symbol that is unique.
To check the data types-
let x = 3;
console.log(typeof x);
EX-
Let firstName = 'vikas';
let lastName = 'singh';
const email = 'vikas828@gmail.com';
let mobNum = 980989898;
let pass = ''328dhdhw8"
let login = true;
console.log(typeof firstName);
console.log(typeof lastName);
console.log(typeof email);
console.log(typeof login);
EX-
let x = 10;
Here, let = keyword and x = variable and 5 is a value here 5 is assign to x it it is hold 5 with help of = operator
Note You can store multiple data types in an array.
let arr1 = ['vik', 'sik', 'liv', 'singh'];