Professional Documents
Culture Documents
Javascript Es6 New Features (1)
Javascript Es6 New Features (1)
Javascript Es6 New Features (1)
ES6
NEW
FEATURE
INTRODUCTIO
N
Explain what is javascirpt
es6 new feature’s all
about?
New Features in ES6
The let keyword String.startsWith()
The const String.endsWith()
keyword Arrow Array.from()
Functions The ... Array keys()
Operator For/of
Array find()
Map Array findIndex()
Objects Set
New Math Methods
Objects
New Number
Classes
Properties New
Promises
Number Methods New
Symbol
Global Methods Object
Default Parameters
Function Rest entries JavaScript
Parameter Modules
String.includes()
WHAT IS
JAVASCRIPT
ES6
ECMAScript 2015 (also known as ES6
and ECMAScript 6) is the second
major revision to JavaScript. It
introduced several new features that
make JavaScript programming more
efficient and expressive.
let
keywords EXAMPLE
The let keyword is used to declare
VAR X =
variables in JavaScript. It was introduced
10;
in ECMAScript 6 (ES6) as an alternative
// HERE
to the var keyword, which had been
X IS 10
used to declare variables in previous {
versions of JavaScript. The main LET X =
difference between let and var is that let 2;
allows for block-scoping, while var // HERE
does not X IS 2
}
// HERE
EXAMPL
CONST
E
CONST PI =
3.141592653589793; PI =
KEYWORD
const is a keyword that was introduced in
ECMAScript 6 (ES6) and is used to declare
3.14; // THIS WILL GIVE a variable that cannot be reassigned1.
Variables declared with const have block
AN ERROR
scope, which means they are only
PI = PI + 10; // THIS accessible within the block they are defined
WILL ALSO in1.
GIVE AN ERROR When you declare a variable with const,
you must assign it a value at the same
time.
Arrow
Functions
Arrow functions allows EXAMPLE
a short syntax for // ES5
VAR X = FUNCTION(X,
writing function
Y) { RETURN X * Y;
expressions. }
You don't need the
function keyword, the // ES6
return keyword, and CONST X = (X, Y) =>
the curly brackets. X * Y;
SPREAD (...) Example
OPSpread
ERATORoperator: The const q1 = ["Jan", "Feb", "Mar"];
const q2 = ["Apr", "May", "Jun"];
spread operator (...) const q3 = ["Jul", "Aug", "Sep"];
expands an iterable const q4 = ["Oct", "Nov",
(like an array) into "May"];
more elements .
For/of loop: The for/of const year =
statement loops through [...q1, ...q2, ...q3, ...q4];
the values of an iterable
object.
For/of looP
The JavaScript for/of statement loops
through the values of an iterable
objects. for/of lets you loop over data
structures that are iterable such as
Arrays, Strings, Maps, NodeLists, and
more.
LOOPING OVER AN ARRAY LOOPING OVER A
Example STRING
Example
const cars = ["BMW", "Volvo", let language =
"Mini"]; let text = ""; "JavaScript"; let text = "";
The Array.from()
The endsWith()
method returns an
method returns true Array object from
if a string ends with any object with a
a specified value, length property or
otherwise false: any iterable object.
ARRAY KEYS() ARRAY
The keys() method
FIND()
The find() method
returns the value of
returns an Array the first array element
Iterator object with that passes a test
the keys of an array. function.
This example finds
(returns the value of )
the first element that
is larger than 18:
ARRAY NEW MATH
FINDINDEX() METHODS
The findIndex() method
returns the index of the ES6 added the
first array element that following methods to
passes a test function. the Math object:
This example finds the Math.trunc()
index of the first Math.sign()
element that is larger Math.cbrt()
than 18: Math.log2()
Math.log10()
NEW NEW
NUMBER NUMBER
PROPERTIES
ES6 added the METHODS
following properties to
the Number object: ES6 added 2 new
EPSILON methods to the
MIN_SAFE_INTEGER Number object:
MAX_SAFE_INTEGER Number.isInteger()
Number.isSafeInteger()
NEW GLOBAL METHODS OBJECT
ENTRIES()
Example
ES6 added 2 new Create an Array Iterator, and then iterate over the key/value
global number pairs: const fruits = ["Banana", "Orange", "Apple", "Mango"];
const f = fruits.entries();
methods:
isFinite() for (let x of f)
isNaN() { document.getElementById("demo").innerHTML +=
x;
}
Modules
Import from named exports
Import named exports from the
file
person.js:
import { name, age } from
"./person.js";
Thank
you