What are Data-Types in JavaScript?
- Data types always represents the type of information variable has.
- Every programming language have their own set of data-types.
- JavaScript also have several data-types but as programmer we usually don’t use them explicitly.
- JavaScript is loosely typed scripting language hence data-type declaration is not required it’ll be resolved internally.
- In case of TypeScript we need to declare data-types explicitly since its stricter version of JavaScript so it’s always better to understand data-types.
How Data-Types are classified in JavaScript?
- In JavaScript data-types are mainly classified into two types i.e. Primitive and Non-Primitive.
- Primitive Data-Types
- String
- Number
- BigInt
- Boolean
- Undefined
- Null
- Symbol
- Non-Primitive data-types
- Object
- Arrays
- Functions
- Dates
- Maps
- Sets
- RegExp
String
- In JavaScript String is used to re-present textual information same like other programming languages.
- JavaScript supports different types string declarations.
- E.g. “Hello”, ‘Hello’, `Hello`
let name = "John";
let city = 'Mumbai';
let message = `Hello ${name}`;
let name = "Akshay";
let age = 30;
console.log(`My name is ${name} and I am ${age} years old.`);
