JavaScript 6 version Feature
JavaScript 6 version Feature
let
> let is a keyword.
> let used as alternative of var keyword.
> by using let we can create local var or global var
> let used for creating a variable with fixed datatype.
Syn: let varname=value;
ex: let a=10;
datatype of a is number, and we can't change datatype in rest of
program.
const
> const is a keyword.
> const kw used for creating a constant variables. means once we assign
any value to variable, we can't change.
Syn: const varname=value;
ex: const a=10;
we can't change value of a var.
Note: while using const keyword, don't use var & let keywords.
String interpolation
>string interpolation replaces the expressions in the string with actual
values of the specified variables.
>operator is ${}
>string should be enclosed with in "backtick" (` `), but not "" and ' '.
Syn: `${var/expr/fun}`
`text ${variable} text ${expr} text ${F/FE/AF} ...`
For in loop
for of loop
Arrow functions
ES6 arrow functions provide you with an alternative way to write a shorter
syntax compared to the function expression.
Specifying parameters:
() => statement
() => { ... } // no parameter
param =>{ ... } // one parameter, an identifier
(param1, param2…) =>{ ... } // several parameters
Specifying a body:
x =>{ return x * x } // block
x => x * x // expression, equivalent to previous line