SlideShare a Scribd company logo
Future of javascript
Getting Started with
ES6
Mohammad Saeed Khan
Naukri | FED
Index
● Motivation: Why should we use ES6 ?
● ES6 Features
● What to be covered next ?
● How to use ES6 Features today ?
Transpilers ( source-to-source Compiler)
● Famous Build Tools
● Grunt Setup
● References
Why should we use ES6 ?
● The syntax is simpler
● It's much easier and less error-prone to set up inheritance
hierarchies using the new syntax than with the old.
● The next-generation of JavaScript will bring a simpler and
friendlier syntax helping the learning process for developers
coming from other OOPs languages.
● Easy to build huge applications for the web in a scalable and
maintainable manner.
● JavaScript has blown up in popularity and is being used in ways
that were never imagined when it was first designed. It’s time for
JavaScript to grow up and become a “real” language.
Evolution always comes with growing pains.
Time to speak up and try out what works for you.
ES6 Features
● Let
● Const
● Class
● Default Function Parameters
● Collections
● Sets
● Maps
● Destructuring
● Object Destructuring
● Rest Parameters
● Spread operators
● Iterators
● Template Strings
● Promises
● Modules
● module loader
● Arrow functions
● proxies
● Symbols
● Generators
● enhanced object literals
● weakmap + weakset
● subclassable built-ins
● math + number + string + array + object APIs
● Array Comprehension
● reflect api
● tail calls
What to be covered in next session...
var jsFuture = "es6";
(function() {
if (!jsFuture) {
let jsFuture = "es5";
}
console.log(jsFuture);
}());
Output: ???
var jsFuture = "es6";
(function() {
if (!jsFuture) {
var jsFuture = "es5";
}
console.log(jsFuture);
}());
Output: ???
ES6ES5
Block Scoping with let
Const
● Class declarations are not hoisted
Classes
Let’s examine three kinds of methods that
you often find in class literals:-
● Prototypes having data properties is generally considered an
anti-pattern, so this just enforces a best practice.
● A class body can only contain methods(constructor, static
methods, prototype methods), but not data properties.
class team{
constructor(name, domain, work) {
this.domain = domain;
this.teamName = name;
this.work = work;
}
summary() {
return this.domain + " " +
this.teamName + " team is really doing " +
this.work + " work";
}
}
function team(name, domain, work) {
this.domain = domain;
this.teamName = name;
this.work = work;
funiton sug()
}
team.prototype.summary = function() {
return this.domain + " " + this.teamName
+ " team is really doing " + this.work + "
work";
}
ES6ES5
var myInstance = new team("frontend", "Naukri", "awesome");
console.log(myInstance.summary());
Class
Class Object
class Company extends team{
constructor(x, y, z, CompanyName) {
super(x,y,z);
this.CompanyName = CompanyName;
}
summary() {
return this.CompanyName+ " is a parent company of "+ this.domain + "
but, " + this.domain+ " " +this.teamName+ " team is really doing "
+this.work+ " work";
}
}
var parentInst = new Company("frontend", "Naukri", "awesome",
"infoedge");
console.log(parentInst.summary())
ES6 Class inheritance
Important Points
console.log(parentInst instanceof Company); // true
console.log(parentInst instanceof team); // true
typeof team // 'function'
team() // TypeError: Classes can’t be function-called
foo(); // works, because ‘foo’ is hoisted
function foo() {}
new Foo(); // ReferenceError
Class Foo{}
function functionThatUsesBar(){
new Bar();
}
functionThatUsesBar(); // ReferenceError
class Bar{};
functionThatUsesBar(); // Ok
Class Expressions
Similarly to functions, there are two ways to define a class:
class declarations and class expressions.
Also similarly to functions, the identifier of a class expression
is only visible within the expression:
const myClass = class team{
getClassName(){
return team.name
}
};
let inst = new myClass();
console.log(inst.getClassName())
console.log(team.name); // ReferenceError: team is not defined
Default Function Parameters
With default function parameters, we can always have function
parameters as an option by setting some default values. The
syntax for this feature in ES6 is extremely intuitive.
The default parameters are defined when the functions are
defined.
function history(lang = "C", year = 1972) {
return lang + " was created around the year " + year;
}
console.log(history());
console.log(history('javascript', "1995"))
Let's have a look at the ES6 syntax below
Collections
ES6 offers new data structures previously not available
in JavaScript
SET & MAP
Collection: SET
Sets are simple data structures that are similar to arrays, but each
value is unique.
var engines = new Set(); // create new Set
engines.add("Gecko"); // add to Set
engines.add("Trident");
engines.add("Webkit");
engines.add("Hippo");
engines.add("Hippo"); // note that Hippo is added twice
console.log("Browser engines include Gecko? " + engines.has("Gecko")); // true
console.log("Browser engines include Hippo? " + engines.has("Hippo")); // true
console.log("Browser engines include Indigo? " + engines.has("Indigo")); // false
engines.delete("Hippo"); // delete item
console.log("Hippo is deleted. Browser engines include Hippo? " +
engines.has("Hippo")); // false
Collection: MAP
● Maps are quite similar to JavaScript object key-value pairs. Using a unique key,
we can retrieve the value.
● In ES6, the key can be any JavaScript data type and not just strings.
var es6 = new Map(); // create new Map
es6.set("edition", 6); // key is string
es6.set(262, "standard"); // key is number
es6.set(undefined, "nah"); // key is undefined
var hello = function() {console.log("hello");};
es6.set(hello, "Hello ES6!"); // key is function
console.log( "Value of 'edition' exits? " + es6.has("edition") ); // true
console.log( "Value of 'year' exits? " + es6.has("years") ); // false
Destructuring
In programming languages, the term "destructuring"
denotes pattern matching.
In ES6, we can do some pretty nifty pattern matching
in arrays and objects that previously would have taken
us more than one step.
Let's explore some of them
● Array destructuring
● Object destructuring
Array Destructuring
With array destructing, we can initialize(not declare) variables at
once, or even swap them instead of having the conventional way of
creating a
var temp; //temporary variable.
var [ start, end ] = ["earth", "moon"] // initialize
console.log(start + " calling " + end); // earth calling moon
[start, end] = [end, start]; // variable swapping
console.log(start + " calling " + end); // moon calling earth
Array Destructuring ...
Destructuring also becomes a useful shorthand when returning
multiple values from a function, as we do not need to wrap around
an object anymore. Also, to skip certain variables, just leave the
array element empty:
function equinox() {
return [20, "March", 2013, 11, 02];
}
var [date, month, , ,] = equinox();
console.log("This year's equinox was on " + date + month);
// This year's equinox was on 20March
By destructuring, variables
can also be initialized from
an object that is returned
from a function even with
deeply nested objects.
Also, just like the array
patterns, we can skip the
ones not needed.
Here's the snippet of code
that illustrates just this:
function equinox2() {
return {
date: 20,
month: "March",
year: 2013,
time: {
hour: 11, // nested
minute: 2
}
};
}
Object destructuring
var { date: d, month: m, time : { hour: h}
} = equinox2();
// h has the value of the nested property
while "year" and "minute" are skipped
totally
console.log("This year's equinox was on " +
d + m + " at " + h); // This year's equinox
was on 20March at 11
Rest Parameters
In ES6, rest parameters allows us to easily use a few fixed
parameters in a function, along with the rest of the trailing and
variable number of parameters.
We already use arguments, which is an array-like object that
defines the arguments passed to a function, but clearly we cannot
use the array function to manipulate these arguments. With a clear
syntax in ES6, it also moves the intent of the developer into the
syntax level with three dots ... to denote a variable number of
arguments.
function push(array, ...items) { // defining rest parameters with 3
dot syntax
items.forEach(function(item) {
array.push(item);
console.log( item );
});
}
// 1 fixed + 4 variable parameters
var planets = [];
console.log("Inner planets of our Solar system are: " );
push(planets, "Mercury", "Venus", "Earth", "Mars"); // rest
parameters
Spread operator
A spread operator is the opposite of rest parameters.
When calling a function, we can pass in the fixed
argument that is needed along with an array of a
variable size with the familiar three dot syntax, to
indicate the variable number of arguments.
// Spread operator "...weblink"
function createURL (comment, path, protocol, subdomain, domain, tld) {
var shoutout = comment + ": " + protocol + "://" + subdomain + "." +
domain + "." + tld + "/" + path;
console.log( shoutout );
}
var weblink = ["hypertext/WWW/TheProject.html", "http", "info", "cern", "ch"],
comment = "World's first Website";
createURL(comment, ...weblink ); // spread operator
In the example below, the function requires six separate
arguments. When calling the function, the data is passed as an
array with the spread operator. Let's see how the syntax looks,
when calling the function with fixed arguments as well as a
variable number of arguments:
Getting started with ES6 : Future of javascript
Iterators→ for-of
var planets = ["Mercury", "Venus", "Earth", "Mars"];
for (let p of planets) {
console.log(p); // Mercury, Venus, Earth, Mars
}
var engines = new Set(["Gecko", "Trident", "Webkit", "Webkit"]);
for (var e of engines) {
console.log(e);
// Set only has unique values, hence Webkit shows only once
}
var es6 = new Map();
es6.set("edition", 6);
es6.set("committee", "TC39");
es6.set("standard", "ECMA-262");
for (var [name, value] of es6) {
console.log(name + ": " + value);
}
Getting started with ES6 : Future of javascript
● Babel - Turn ES6+ code into vanilla ES5 with no runtime
● Traceur compiler - ES6 features > ES5. Includes classes, generators,
promises, destructuring patterns, default parameters & more.
● es6ify - Traceur compiler wrapped as a Browserify v2 transform
● babelify - Babel transpiler wrapped as a Browserify transform
● es6-transpiler - ES6 > ES5. Includes classes, destructuring, default
parameters, spread
● Square's es6-module-transpiler - ES6 modules to AMD or CJS
● Facebook's regenerator - transform ES6 yield/generator functions to
ES5
● Facebook's jstransform - A simple utility for pluggable JS syntax
transforms. Comes with a small set of ES6 -> ES5 transforms
● defs - ES6 block-scoped const and let variables to ES3 vars
● es6_module_transpiler-rails - ES6 Modules in the Rails Asset Pipeline
● Some Sweet.js macros that compile from ES6 to ES5
● Bitovi's transpile - Converts ES6 to AMD, CJS, and StealJS.
Transpilers ( source-to-source Compiler)
Famous Build Tools
● Grunt
● Webpack
● Gulp
● Broccoli
● Brunch
Grunt Setup: convert ES6 to ES5 using bebel
Add below dependencies in package.json file
and run: npm install
// package.json
{
"babel-preset-es2015": "^6.1.18",
"grunt-babel": "^6.0.0",
"load-grunt-tasks": "^3.3.0”
}
or run:
npm install grunt-babel, babel-preset-es2015,
load-grunt-tasks
babel: {
options: {
sourceMap: true,
presets: ['es2015']
},
build: {
files: [{
expand: true, // Enable dynamic expansion
cwd: 'src/jass', // Src matches are relative to
this path
src: ['**/*.js'], // Actual patterns to match
dest: 'src/j'
}]
}
}
Resources
Brendan Eich
Addy Osmani
Ariya Hidayat
Nicholas Zakas
Axel Rauschmayer
Brandon Benvie
ECMAScript 6 support in Mozilla
Draft specification for ES.next
The Future of JavaScript, a video by Dave Herman
ECMAScript 6 - The Refined Parts (video and slides) by Kit Cambridge
Latest Tweets on ES mailing list
es6 - my fav parts
ES6 has proper tail calls
Power of Getters
ECMAScript 6
ES6 deep Dive by Dave Herman
Classes
https://github.com/addyosmani/es6-tools
... in depth..
Thank you…
Any Query ?
Ad

Recommended

PDF
Adding ES6 to Your Developer Toolbox
Jeff Strauss
 
PDF
Effective ES6
Teppei Sato
 
PDF
Es.next
Ignacio Gil
 
PPTX
5 Tips for Better JavaScript
Todd Anglin
 
PDF
JRuby, Ruby, Rails and You on the Cloud
Hiro Asari
 
PDF
Spring into rails
Hiro Asari
 
PDF
ECMAScript 6
偉格 高
 
PPTX
Introduction to es6
NexThoughts Technologies
 
PDF
JS Level Up: Prototypes
Vernon Kesner
 
PDF
Yii, frameworks and where PHP is heading to
Alexander Makarov
 
PDF
JRuby and You
Hiro Asari
 
PDF
The Beauty Of Java Script V5a
rajivmordani
 
PDF
The Beauty of Java Script
Michael Girouard
 
PDF
Pi
Hiro Asari
 
PDF
Introduction to CoffeeScript
Stalin Thangaraj
 
PDF
Javascript - The Good, the Bad and the Ugly
Thorsten Suckow-Homberg
 
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
PDF
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
Mathias Bynens
 
PDF
ORMs in Golang
Ikenna Okpala
 
PPTX
Node.js for PHP developers
Andrew Eddie
 
KEY
Sprockets
Christophe Porteneuve
 
PDF
CoffeeScript
Eddie Kao
 
PDF
New ES6 Hotness
Pawel Szymczykowski
 
PDF
Ezobject wrapper workshop
Kaliop-slide
 
PDF
JRuby @ Boulder Ruby
Nick Sieger
 
PDF
Event Driven Javascript
Federico Galassi
 
PDF
The Enterprise Strikes Back
Burke Libbey
 
PDF
Connecting the Worlds of Java and Ruby with JRuby
Nick Sieger
 
PPTX
JavaScript : What is it really? AND Some new features in ES6
Aayush Shrestha
 
PDF
Prototypeベース in JavaScript
Ryo Maruyama
 

More Related Content

What's hot (20)

PDF
JS Level Up: Prototypes
Vernon Kesner
 
PDF
Yii, frameworks and where PHP is heading to
Alexander Makarov
 
PDF
JRuby and You
Hiro Asari
 
PDF
The Beauty Of Java Script V5a
rajivmordani
 
PDF
The Beauty of Java Script
Michael Girouard
 
PDF
Pi
Hiro Asari
 
PDF
Introduction to CoffeeScript
Stalin Thangaraj
 
PDF
Javascript - The Good, the Bad and the Ugly
Thorsten Suckow-Homberg
 
PDF
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
PDF
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
Mathias Bynens
 
PDF
ORMs in Golang
Ikenna Okpala
 
PPTX
Node.js for PHP developers
Andrew Eddie
 
KEY
Sprockets
Christophe Porteneuve
 
PDF
CoffeeScript
Eddie Kao
 
PDF
New ES6 Hotness
Pawel Szymczykowski
 
PDF
Ezobject wrapper workshop
Kaliop-slide
 
PDF
JRuby @ Boulder Ruby
Nick Sieger
 
PDF
Event Driven Javascript
Federico Galassi
 
PDF
The Enterprise Strikes Back
Burke Libbey
 
PDF
Connecting the Worlds of Java and Ruby with JRuby
Nick Sieger
 
JS Level Up: Prototypes
Vernon Kesner
 
Yii, frameworks and where PHP is heading to
Alexander Makarov
 
JRuby and You
Hiro Asari
 
The Beauty Of Java Script V5a
rajivmordani
 
The Beauty of Java Script
Michael Girouard
 
Introduction to CoffeeScript
Stalin Thangaraj
 
Javascript - The Good, the Bad and the Ugly
Thorsten Suckow-Homberg
 
Workshop 4: NodeJS. Express Framework & MongoDB.
Visual Engineering
 
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
Mathias Bynens
 
ORMs in Golang
Ikenna Okpala
 
Node.js for PHP developers
Andrew Eddie
 
CoffeeScript
Eddie Kao
 
New ES6 Hotness
Pawel Szymczykowski
 
Ezobject wrapper workshop
Kaliop-slide
 
JRuby @ Boulder Ruby
Nick Sieger
 
Event Driven Javascript
Federico Galassi
 
The Enterprise Strikes Back
Burke Libbey
 
Connecting the Worlds of Java and Ruby with JRuby
Nick Sieger
 

Viewers also liked (20)

PPTX
JavaScript : What is it really? AND Some new features in ES6
Aayush Shrestha
 
PDF
Prototypeベース in JavaScript
Ryo Maruyama
 
PDF
JavaScript 実践講座 Framework, Tool, Performance
クラスメソッド株式会社
 
PDF
JavaScript.Next Returns
dynamis
 
PDF
FileReader and canvas and server silde
Net Kanayan
 
PDF
ES6 はじめました
Net Kanayan
 
PDF
kontainer-js
Kuu Miyazaki
 
PDF
150421 es6とかな話
kotaro_hirayama
 
PDF
jQuery勉強会#4
Ryo Maruyama
 
PPTX
ES6 - JavaCro 2016
Nenad Pecanac
 
PPTX
Startup JavaScript
Akinari Tsugo
 
PPT
Google App EngineでTwitterアプリを作ろう
kenji4569
 
PDF
ECMAScript 6 Features(PDF 版)
taskie
 
PDF
はじめてのWallaby.js
Shunta Saito
 
PDF
Hello npm
Muyuu Fujita
 
PPTX
Nds meetup8 lt
ushiboy
 
PDF
アニメーションの実装つらい話
kata shin
 
PDF
断言して間違えると信頼度が低下するというベイズの話
Junya Hayashi
 
PDF
Learn ES2015
Muyuu Fujita
 
PDF
Bacon.jsではじめる関数型リアアクティブプログラミング入門 with ES6
Haraguchi Go
 
JavaScript : What is it really? AND Some new features in ES6
Aayush Shrestha
 
Prototypeベース in JavaScript
Ryo Maruyama
 
JavaScript 実践講座 Framework, Tool, Performance
クラスメソッド株式会社
 
JavaScript.Next Returns
dynamis
 
FileReader and canvas and server silde
Net Kanayan
 
ES6 はじめました
Net Kanayan
 
kontainer-js
Kuu Miyazaki
 
150421 es6とかな話
kotaro_hirayama
 
jQuery勉強会#4
Ryo Maruyama
 
ES6 - JavaCro 2016
Nenad Pecanac
 
Startup JavaScript
Akinari Tsugo
 
Google App EngineでTwitterアプリを作ろう
kenji4569
 
ECMAScript 6 Features(PDF 版)
taskie
 
はじめてのWallaby.js
Shunta Saito
 
Hello npm
Muyuu Fujita
 
Nds meetup8 lt
ushiboy
 
アニメーションの実装つらい話
kata shin
 
断言して間違えると信頼度が低下するというベイズの話
Junya Hayashi
 
Learn ES2015
Muyuu Fujita
 
Bacon.jsではじめる関数型リアアクティブプログラミング入門 with ES6
Haraguchi Go
 
Ad

Similar to Getting started with ES6 : Future of javascript (20)

PDF
JavaScript in 2016
Codemotion
 
PPTX
JavaScript in 2016 (Codemotion Rome)
Eduard Tomàs
 
PPTX
Getting started with ES6
Nitay Neeman
 
PDF
Es6 to es5
Shakhzod Tojiyev
 
PDF
Idiomatic Javascript (ES5 to ES2015+)
David Atchley
 
PDF
Impress Your Friends with EcmaScript 2015
Lukas Ruebbelke
 
PPTX
The ES Library for JavaScript Developers
Ganesh Bhosale
 
PPTX
ES6: Features + Rails
Santosh Wadghule
 
PDF
Internal workshop es6_2015
Miguel Ruiz Rodriguez
 
PDF
Fitc whats new in es6 for web devs
FITC
 
PDF
What's New in ES6 for Web Devs
Rami Sayar
 
PPTX
ES6 and BEYOND
Brian Patterson
 
PDF
ES6: The future is now
Sebastiano Armeli
 
PPTX
ECMAScript 2015
Sebastian Pederiva
 
PDF
ES6 General Introduction
Thomas Johnston
 
PDF
MCS First Year JavaScript ES6 Features.pdf
KavitaSawant18
 
PPTX
Es6 day1
Abhishek Sharma
 
PPTX
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PPTX
Next Generation of Javascript
Squash Apps Pvt Ltd
 
PDF
JavaScript ES6
Leo Hernandez
 
JavaScript in 2016
Codemotion
 
JavaScript in 2016 (Codemotion Rome)
Eduard Tomàs
 
Getting started with ES6
Nitay Neeman
 
Es6 to es5
Shakhzod Tojiyev
 
Idiomatic Javascript (ES5 to ES2015+)
David Atchley
 
Impress Your Friends with EcmaScript 2015
Lukas Ruebbelke
 
The ES Library for JavaScript Developers
Ganesh Bhosale
 
ES6: Features + Rails
Santosh Wadghule
 
Internal workshop es6_2015
Miguel Ruiz Rodriguez
 
Fitc whats new in es6 for web devs
FITC
 
What's New in ES6 for Web Devs
Rami Sayar
 
ES6 and BEYOND
Brian Patterson
 
ES6: The future is now
Sebastiano Armeli
 
ECMAScript 2015
Sebastian Pederiva
 
ES6 General Introduction
Thomas Johnston
 
MCS First Year JavaScript ES6 Features.pdf
KavitaSawant18
 
Es6 day1
Abhishek Sharma
 
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Next Generation of Javascript
Squash Apps Pvt Ltd
 
JavaScript ES6
Leo Hernandez
 
Ad

More from Mohd Saeed (6)

PPTX
Web components
Mohd Saeed
 
PDF
Suggest.js
Mohd Saeed
 
PPTX
JS basics
Mohd Saeed
 
PPTX
Raphael.js
Mohd Saeed
 
PPSX
Erp by Mohammad Saeed Khan
Mohd Saeed
 
PPTX
ERP by saeed
Mohd Saeed
 
Web components
Mohd Saeed
 
Suggest.js
Mohd Saeed
 
JS basics
Mohd Saeed
 
Raphael.js
Mohd Saeed
 
Erp by Mohammad Saeed Khan
Mohd Saeed
 
ERP by saeed
Mohd Saeed
 

Recently uploaded (20)

PDF
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PPTX
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PDF
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
PDF
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
PDF
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
PDF
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
PDF
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
PDF
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
PPTX
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
PPTX
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
PDF
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
PDF
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
PDF
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 

Getting started with ES6 : Future of javascript

  • 1. Future of javascript Getting Started with ES6 Mohammad Saeed Khan Naukri | FED
  • 2. Index ● Motivation: Why should we use ES6 ? ● ES6 Features ● What to be covered next ? ● How to use ES6 Features today ? Transpilers ( source-to-source Compiler) ● Famous Build Tools ● Grunt Setup ● References
  • 3. Why should we use ES6 ? ● The syntax is simpler ● It's much easier and less error-prone to set up inheritance hierarchies using the new syntax than with the old. ● The next-generation of JavaScript will bring a simpler and friendlier syntax helping the learning process for developers coming from other OOPs languages. ● Easy to build huge applications for the web in a scalable and maintainable manner. ● JavaScript has blown up in popularity and is being used in ways that were never imagined when it was first designed. It’s time for JavaScript to grow up and become a “real” language.
  • 4. Evolution always comes with growing pains. Time to speak up and try out what works for you.
  • 5. ES6 Features ● Let ● Const ● Class ● Default Function Parameters ● Collections ● Sets ● Maps ● Destructuring ● Object Destructuring ● Rest Parameters ● Spread operators ● Iterators
  • 6. ● Template Strings ● Promises ● Modules ● module loader ● Arrow functions ● proxies ● Symbols ● Generators ● enhanced object literals ● weakmap + weakset ● subclassable built-ins ● math + number + string + array + object APIs ● Array Comprehension ● reflect api ● tail calls What to be covered in next session...
  • 7. var jsFuture = "es6"; (function() { if (!jsFuture) { let jsFuture = "es5"; } console.log(jsFuture); }()); Output: ??? var jsFuture = "es6"; (function() { if (!jsFuture) { var jsFuture = "es5"; } console.log(jsFuture); }()); Output: ??? ES6ES5 Block Scoping with let
  • 9. ● Class declarations are not hoisted Classes Let’s examine three kinds of methods that you often find in class literals:- ● Prototypes having data properties is generally considered an anti-pattern, so this just enforces a best practice. ● A class body can only contain methods(constructor, static methods, prototype methods), but not data properties.
  • 10. class team{ constructor(name, domain, work) { this.domain = domain; this.teamName = name; this.work = work; } summary() { return this.domain + " " + this.teamName + " team is really doing " + this.work + " work"; } } function team(name, domain, work) { this.domain = domain; this.teamName = name; this.work = work; funiton sug() } team.prototype.summary = function() { return this.domain + " " + this.teamName + " team is really doing " + this.work + " work"; } ES6ES5 var myInstance = new team("frontend", "Naukri", "awesome"); console.log(myInstance.summary()); Class
  • 12. class Company extends team{ constructor(x, y, z, CompanyName) { super(x,y,z); this.CompanyName = CompanyName; } summary() { return this.CompanyName+ " is a parent company of "+ this.domain + " but, " + this.domain+ " " +this.teamName+ " team is really doing " +this.work+ " work"; } } var parentInst = new Company("frontend", "Naukri", "awesome", "infoedge"); console.log(parentInst.summary()) ES6 Class inheritance
  • 13. Important Points console.log(parentInst instanceof Company); // true console.log(parentInst instanceof team); // true typeof team // 'function' team() // TypeError: Classes can’t be function-called foo(); // works, because ‘foo’ is hoisted function foo() {} new Foo(); // ReferenceError Class Foo{} function functionThatUsesBar(){ new Bar(); } functionThatUsesBar(); // ReferenceError class Bar{}; functionThatUsesBar(); // Ok
  • 14. Class Expressions Similarly to functions, there are two ways to define a class: class declarations and class expressions. Also similarly to functions, the identifier of a class expression is only visible within the expression: const myClass = class team{ getClassName(){ return team.name } }; let inst = new myClass(); console.log(inst.getClassName()) console.log(team.name); // ReferenceError: team is not defined
  • 15. Default Function Parameters With default function parameters, we can always have function parameters as an option by setting some default values. The syntax for this feature in ES6 is extremely intuitive. The default parameters are defined when the functions are defined. function history(lang = "C", year = 1972) { return lang + " was created around the year " + year; } console.log(history()); console.log(history('javascript', "1995")) Let's have a look at the ES6 syntax below
  • 16. Collections ES6 offers new data structures previously not available in JavaScript SET & MAP
  • 17. Collection: SET Sets are simple data structures that are similar to arrays, but each value is unique. var engines = new Set(); // create new Set engines.add("Gecko"); // add to Set engines.add("Trident"); engines.add("Webkit"); engines.add("Hippo"); engines.add("Hippo"); // note that Hippo is added twice console.log("Browser engines include Gecko? " + engines.has("Gecko")); // true console.log("Browser engines include Hippo? " + engines.has("Hippo")); // true console.log("Browser engines include Indigo? " + engines.has("Indigo")); // false engines.delete("Hippo"); // delete item console.log("Hippo is deleted. Browser engines include Hippo? " + engines.has("Hippo")); // false
  • 18. Collection: MAP ● Maps are quite similar to JavaScript object key-value pairs. Using a unique key, we can retrieve the value. ● In ES6, the key can be any JavaScript data type and not just strings. var es6 = new Map(); // create new Map es6.set("edition", 6); // key is string es6.set(262, "standard"); // key is number es6.set(undefined, "nah"); // key is undefined var hello = function() {console.log("hello");}; es6.set(hello, "Hello ES6!"); // key is function console.log( "Value of 'edition' exits? " + es6.has("edition") ); // true console.log( "Value of 'year' exits? " + es6.has("years") ); // false
  • 19. Destructuring In programming languages, the term "destructuring" denotes pattern matching. In ES6, we can do some pretty nifty pattern matching in arrays and objects that previously would have taken us more than one step. Let's explore some of them ● Array destructuring ● Object destructuring
  • 20. Array Destructuring With array destructing, we can initialize(not declare) variables at once, or even swap them instead of having the conventional way of creating a var temp; //temporary variable. var [ start, end ] = ["earth", "moon"] // initialize console.log(start + " calling " + end); // earth calling moon [start, end] = [end, start]; // variable swapping console.log(start + " calling " + end); // moon calling earth
  • 21. Array Destructuring ... Destructuring also becomes a useful shorthand when returning multiple values from a function, as we do not need to wrap around an object anymore. Also, to skip certain variables, just leave the array element empty: function equinox() { return [20, "March", 2013, 11, 02]; } var [date, month, , ,] = equinox(); console.log("This year's equinox was on " + date + month); // This year's equinox was on 20March
  • 22. By destructuring, variables can also be initialized from an object that is returned from a function even with deeply nested objects. Also, just like the array patterns, we can skip the ones not needed. Here's the snippet of code that illustrates just this: function equinox2() { return { date: 20, month: "March", year: 2013, time: { hour: 11, // nested minute: 2 } }; } Object destructuring var { date: d, month: m, time : { hour: h} } = equinox2(); // h has the value of the nested property while "year" and "minute" are skipped totally console.log("This year's equinox was on " + d + m + " at " + h); // This year's equinox was on 20March at 11
  • 23. Rest Parameters In ES6, rest parameters allows us to easily use a few fixed parameters in a function, along with the rest of the trailing and variable number of parameters. We already use arguments, which is an array-like object that defines the arguments passed to a function, but clearly we cannot use the array function to manipulate these arguments. With a clear syntax in ES6, it also moves the intent of the developer into the syntax level with three dots ... to denote a variable number of arguments.
  • 24. function push(array, ...items) { // defining rest parameters with 3 dot syntax items.forEach(function(item) { array.push(item); console.log( item ); }); } // 1 fixed + 4 variable parameters var planets = []; console.log("Inner planets of our Solar system are: " ); push(planets, "Mercury", "Venus", "Earth", "Mars"); // rest parameters
  • 25. Spread operator A spread operator is the opposite of rest parameters. When calling a function, we can pass in the fixed argument that is needed along with an array of a variable size with the familiar three dot syntax, to indicate the variable number of arguments.
  • 26. // Spread operator "...weblink" function createURL (comment, path, protocol, subdomain, domain, tld) { var shoutout = comment + ": " + protocol + "://" + subdomain + "." + domain + "." + tld + "/" + path; console.log( shoutout ); } var weblink = ["hypertext/WWW/TheProject.html", "http", "info", "cern", "ch"], comment = "World's first Website"; createURL(comment, ...weblink ); // spread operator In the example below, the function requires six separate arguments. When calling the function, the data is passed as an array with the spread operator. Let's see how the syntax looks, when calling the function with fixed arguments as well as a variable number of arguments:
  • 28. Iterators→ for-of var planets = ["Mercury", "Venus", "Earth", "Mars"]; for (let p of planets) { console.log(p); // Mercury, Venus, Earth, Mars } var engines = new Set(["Gecko", "Trident", "Webkit", "Webkit"]); for (var e of engines) { console.log(e); // Set only has unique values, hence Webkit shows only once } var es6 = new Map(); es6.set("edition", 6); es6.set("committee", "TC39"); es6.set("standard", "ECMA-262"); for (var [name, value] of es6) { console.log(name + ": " + value); }
  • 30. ● Babel - Turn ES6+ code into vanilla ES5 with no runtime ● Traceur compiler - ES6 features > ES5. Includes classes, generators, promises, destructuring patterns, default parameters & more. ● es6ify - Traceur compiler wrapped as a Browserify v2 transform ● babelify - Babel transpiler wrapped as a Browserify transform ● es6-transpiler - ES6 > ES5. Includes classes, destructuring, default parameters, spread ● Square's es6-module-transpiler - ES6 modules to AMD or CJS ● Facebook's regenerator - transform ES6 yield/generator functions to ES5 ● Facebook's jstransform - A simple utility for pluggable JS syntax transforms. Comes with a small set of ES6 -> ES5 transforms ● defs - ES6 block-scoped const and let variables to ES3 vars ● es6_module_transpiler-rails - ES6 Modules in the Rails Asset Pipeline ● Some Sweet.js macros that compile from ES6 to ES5 ● Bitovi's transpile - Converts ES6 to AMD, CJS, and StealJS. Transpilers ( source-to-source Compiler)
  • 31. Famous Build Tools ● Grunt ● Webpack ● Gulp ● Broccoli ● Brunch
  • 32. Grunt Setup: convert ES6 to ES5 using bebel Add below dependencies in package.json file and run: npm install // package.json { "babel-preset-es2015": "^6.1.18", "grunt-babel": "^6.0.0", "load-grunt-tasks": "^3.3.0” } or run: npm install grunt-babel, babel-preset-es2015, load-grunt-tasks babel: { options: { sourceMap: true, presets: ['es2015'] }, build: { files: [{ expand: true, // Enable dynamic expansion cwd: 'src/jass', // Src matches are relative to this path src: ['**/*.js'], // Actual patterns to match dest: 'src/j' }] } }
  • 33. Resources Brendan Eich Addy Osmani Ariya Hidayat Nicholas Zakas Axel Rauschmayer Brandon Benvie ECMAScript 6 support in Mozilla Draft specification for ES.next The Future of JavaScript, a video by Dave Herman ECMAScript 6 - The Refined Parts (video and slides) by Kit Cambridge Latest Tweets on ES mailing list es6 - my fav parts ES6 has proper tail calls Power of Getters ECMAScript 6 ES6 deep Dive by Dave Herman Classes https://github.com/addyosmani/es6-tools ... in depth..

Editor's Notes

  • #13: super([arguments]); // calls the parent constructor. super.functionOnParent([arguments]); When used in a constructor, the super keyword appears alone and must be used before the this keyword can be used. This keyword can also be used to call functions on a parent object.
  • #31: babelify - Babel transpiler wrapped as a Browserify transform