Javascript ES6 Datatypes
In javascript, we can't define datatype for any variables and constants, It can allow to set any datatype. So in Javascript, we can define variables and constants using var, Let and Const.Var: Everyone knows about the var keyword. It's used to define a variable. It supports functional scope. Variables defined with var are hoisted to the top.
[// can not use fruitName
function myFunction() {
var fruitName = "Apple";
// can use fruitName
}
// can not use fruitName]
Const: It's also used to define a Constants in javascript. but it supports block scope. const variables must be assigned a value when they are declared. Variables defined with const are not hoisted to the top. Primitive values can't be changed/reassigned. You can change the properties of an object and elements of a constant array.
[// You can create a constant array:Let: It's also used to define a variable in javascript. but it supports block scope. Variables defined with let are not hoisted to the top.
const cars = ["Apple", "Banana", "Grapes"];
// You can change an element:
cars[0] = "kiwi";
// You can add an element:
cars.push("Orange");]
[{
let x = 1;
}
// x can be used here]
COMMENTS