SlideShare a Scribd company logo
Moving Ahead With
JavaScript v6
- Gaurav Behere
- http://www.gauravbehere.in
1. Quick Glance On JavaScript Evolution.
2. What is ES6 ?
3. Why Should We Bother?
4. Q/A.
JavaScript Evolution
JavaScript, was created in 10 days in May 1995 by Brendan Eich, working at Netscape and now of
Mozilla. JavaScript was not always known as JavaScript: the original name was Mocha, a name
chosen by Marc Andreessen, founder of Netscape.
In September of 1995 the name was changed to LiveScript, then in December of the same year,
upon receiving a trademark license from Sun, the name JavaScript was adopted. This was
somewhat of a marketing move at the time, with Java being very popular around then.
In 1996 - 1997 JavaScript was taken to ECMA to carve out a standard specification, which other
browser vendors could then implement based on the work done at Netscape. The work done over
this period of time eventually led to the official release of ECMA-262 Ed.1: ECMAScript is the
name of the official standard, with JavaScript being the most well known of the implementations.
ActionScript 3 is another well-known implementation of ECMAScript.
In July of 2008 the disparate parties on either side came together in Oslo. This led to the eventual
agreement in early 2009 to rename ECMAScript 3.1 to ECMAScript 5 and drive the language
forward using an agenda that is known as Harmony.
Current status: ECMA 6 draft is ready & published with pending approvals.
http://people.mozilla.org/~jorendorff/es6-draft.html
Compatibility:
https://kangax.github.io/compat-table/es6/
What is in ES6 ?
Highlights:
1. Better syntax, more verbose.
2. Modules, AMD, Async Module Definition.
3. Developer friendly APIs.
4. Better code structuring.
5. Lesser effort/ number of lines than JS v5.
A Bit of Deep Dive
De-structuring – A new and flexible way to assign values from arrays or objects into
variables.
Array de-structuring
var foo = ["one", "two"];
// without destructuring
var one = foo[0];
var two = foo[1];
// with destructuring
var [one, two] = foo;
Object de-structuring
var o = {p: 42, q: true};
var {p, q} = o;
console.log(p); // 42
console.log(q); // true
Block-level scope – ES6 now supports scoping variables to blocks (if, for, while, etc.) using
the let keyword.
Note: Variables declared by let have as their scope the block in which they are defined, as
well as in any contained sub-blocks. In this way, let works very much like var. The main
difference is that the scope of a var variable is the entire enclosing function.
Eg:
function varTest() {
var x = 31;
if (true) {
var x = 71; // same variable!
console.log(x); // 71
}
console.log(x); // 71
}
function letTest() {
let x = 31;
if (true) {
let x = 71; // different variable
console.log(x); // 71
}
console.log(x); // 31
}
Classes – ES6 classes provide a way to encapsulate and extend code.
Note: ES6 has only added a syntactical change to this as a function in JavaScript behaves as
a class.
Eg:
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
Constants – You can now define constants in ES6 code using the const keyword. (This is
already provided by Chrome since long)
Eg:
const my_fav = 7;
Default parameters – Ever wished that a function parameter could be assigned a default
value? You can do that now in ES6.
Eg:
function multiply(a, b = 1) {
return a*b;
}
multiply(5); // 5
Map – Dictionary type object that can be used to store key/value pairs.
Note: We were using array’s associative property to serve as a map, but this had limitations
like getting length & iteration was dependent on Object.keys
Eg:
var myMap = new Map();
myMap.set(“myKey”, “myValue”)
myMap.get(“myKey”); // “myValue”
Modules – Provides a modular way of organizing and loading code.
The usage & module definition is on the lines of commonJS.
Eg:
//File module.js
var someFunction(){
…..
}
var myModule = function(){
return someFunction()
}
export myModule;
//file client.js
Import myModule from ‘module.js’
myModule();
Promises – Used with asynchronous operations. Because async operations still have
problems.
Syntax:
new Promise(function(resolve, reject) { ... });
Rest parameters – Replaces the need for using arguments to access functions arguments.
Allows you to get to an array representing “the rest of the parameters”.
Eg:
function fun1(...theArgs) {
console.log(theArgs.length);
}
fun1(); // 0
fun1(5); // 1
fun1(5, 6, 7); // 3
Arrow functions – A short-hand version of writing an anonymous function.
Syntax:
([param] [, param]) => {
statements
}
param => expression
Eg:
var a2 = a.map(function(s){ return s.length });
Can be reduced to:
var a3 = a.map( s => s.length );
Generators – Specialized functions that can be paused & restarted & can be used as iterators,
declared using function* and the yield keyword.
Note: Calling a generator function does not execute its body immediately; an iterator object for the
function is returned instead. When the iterator's next() method is called, the generator function's
body is executed until the first yield expression, which specifies the value to be returned from the
iterator or, with yield*, delegates to another generator function. The next() method returns an object
with a value property containing the yielded value and a done property which indicates whether the
generator has yielded its last value
Run..Stop..Run
Syntax:
function* name([param[, param[, ... param]]]) {
statements
yield value;
}
Name.next().value;
Eg:
function* idMaker(){
var index = 0;
while(index < 3)
yield index++;
}
var gen = idMaker();
console.log(gen.next().value); // 0
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // undefined
….
Why Should We Bother ?
1. It is the future & we want to remain in the race.
2. Terminology & the language in which developers, websites,
blogs, references etc talk, will change.
3. Most importantly : The libraries which we are currently
depending on, are changing and adapting ES6 features.
Our ground is going to shake, let’s be prepared.
4. Dependency on requireJS for AMD, Kriskowal’s q for
Promises, Underscore for better Collection Processing etc
will be gone
Angular 2.0
1. Usage of classes.
2. Usage of modules.
3. Arrow functions.
4. Default parameters.
5. Rest parameters.
6. No controllers, scopes or
directives
Do watch : ES6 in Angular 2.0 by Erik Arvidsson at ng-europe 2014
https://www.youtube.com/watch?v=iij5RHKi66o
And Angular 2.0 Core by Igor Minar & Tobias Bosch at ng-europe 2014
https://www.youtube.com/watch?v=gNmWybAyBHI
Advertisement Time !!!

More Related Content

KEY
Grand Central Dispatch Design Patterns
KEY
Automatic Reference Counting
PPTX
Grand Central Dispatch
ODP
Scala lens: An introduction
PPTX
Pune-Cocoa: Blocks and GCD
ODP
Pfm technical-inside
ODP
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
PPTX
The CoFX Data Model
Grand Central Dispatch Design Patterns
Automatic Reference Counting
Grand Central Dispatch
Scala lens: An introduction
Pune-Cocoa: Blocks and GCD
Pfm technical-inside
Ruby C extensions at the Ruby drink-up of Sophia, April 2012
The CoFX Data Model

What's hot (20)

PDF
CoffeeScript - TechTalk 21/10/2013
PPT
iOS Multithreading
PDF
GCD and OperationQueue.
PDF
How to build to do app using vue composition api and vuex 4 with typescript
KEY
Dispatch in Clojure
PPTX
ECMAScript 6 and the Node Driver
PPT
eXo SEA - JavaScript Introduction Training
PDF
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
PPTX
Clojure Fundamentals Course For Beginners
PPTX
Java module configuration
PDF
Multithreading and Parallelism on iOS [MobOS 2013]
PDF
Complete Java Course
PPT
JavaScript - An Introduction
PDF
Introduction to asynchronous DB access using Node.js and MongoDB
PPTX
PDF
JRuby @ Boulder Ruby
PPTX
Automating with ansible (Part A)
PPTX
WPF and Prism 4.1 Workshop at BASTA Austria
PPT
JavaScript Basics
PDF
Java fork join
CoffeeScript - TechTalk 21/10/2013
iOS Multithreading
GCD and OperationQueue.
How to build to do app using vue composition api and vuex 4 with typescript
Dispatch in Clojure
ECMAScript 6 and the Node Driver
eXo SEA - JavaScript Introduction Training
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Clojure Fundamentals Course For Beginners
Java module configuration
Multithreading and Parallelism on iOS [MobOS 2013]
Complete Java Course
JavaScript - An Introduction
Introduction to asynchronous DB access using Node.js and MongoDB
JRuby @ Boulder Ruby
Automating with ansible (Part A)
WPF and Prism 4.1 Workshop at BASTA Austria
JavaScript Basics
Java fork join
Ad

Viewers also liked (8)

PDF
Short intro to ES6 Features
PPTX
ES6: Features + Rails
PDF
Javascript Best Practice
PPT
Javascript and Jquery Best practices
PDF
Intro to ES6 / ES2015
PPTX
10 Useful New Features of ECMA Script 6
PDF
Intro to testing Javascript with jasmine
ODP
Object-Oriented Javascript
Short intro to ES6 Features
ES6: Features + Rails
Javascript Best Practice
Javascript and Jquery Best practices
Intro to ES6 / ES2015
10 Useful New Features of ECMA Script 6
Intro to testing Javascript with jasmine
Object-Oriented Javascript
Ad

Similar to Intro to ES6 and why should you bother ! (20)

PPTX
ES6 - JavaCro 2016
PPTX
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
PDF
[2015/2016] JavaScript
KEY
JavaScript Growing Up
PPTX
Module design pattern i.e. express js
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
PPTX
ReactJS.pptx
PPTX
Modern JS with ES6
PPT
PPTX
ECMAScript 2015
PPT
Smoothing Your Java with DSLs
PPTX
React & Redux JS
KEY
A tour on ruby and friends
PDF
Advanced Node.JS Meetup
PPTX
A few good JavaScript development tools
PDF
Global objects in Node.pdf
PPTX
Node.js Patterns for Discerning Developers
PDF
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
PPTX
Angular JS in 2017
PPTX
Modern frontend in react.js
ES6 - JavaCro 2016
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
[2015/2016] JavaScript
JavaScript Growing Up
Module design pattern i.e. express js
WebNet Conference 2012 - Designing complex applications using html5 and knock...
ReactJS.pptx
Modern JS with ES6
ECMAScript 2015
Smoothing Your Java with DSLs
React & Redux JS
A tour on ruby and friends
Advanced Node.JS Meetup
A few good JavaScript development tools
Global objects in Node.pdf
Node.js Patterns for Discerning Developers
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
Angular JS in 2017
Modern frontend in react.js

Recently uploaded (20)

PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
PPT on Performance Review to get promotions
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
web development for engineering and engineering
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
CH1 Production IntroductoryConcepts.pptx
PPT
Mechanical Engineering MATERIALS Selection
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPT on Performance Review to get promotions
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
UNIT 4 Total Quality Management .pptx
web development for engineering and engineering
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
R24 SURVEYING LAB MANUAL for civil enggi
Operating System & Kernel Study Guide-1 - converted.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Automation-in-Manufacturing-Chapter-Introduction.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Lecture Notes Electrical Wiring System Components
CH1 Production IntroductoryConcepts.pptx
Mechanical Engineering MATERIALS Selection

Intro to ES6 and why should you bother !

  • 1. Moving Ahead With JavaScript v6 - Gaurav Behere - http://www.gauravbehere.in
  • 2. 1. Quick Glance On JavaScript Evolution. 2. What is ES6 ? 3. Why Should We Bother? 4. Q/A.
  • 3. JavaScript Evolution JavaScript, was created in 10 days in May 1995 by Brendan Eich, working at Netscape and now of Mozilla. JavaScript was not always known as JavaScript: the original name was Mocha, a name chosen by Marc Andreessen, founder of Netscape. In September of 1995 the name was changed to LiveScript, then in December of the same year, upon receiving a trademark license from Sun, the name JavaScript was adopted. This was somewhat of a marketing move at the time, with Java being very popular around then. In 1996 - 1997 JavaScript was taken to ECMA to carve out a standard specification, which other browser vendors could then implement based on the work done at Netscape. The work done over this period of time eventually led to the official release of ECMA-262 Ed.1: ECMAScript is the name of the official standard, with JavaScript being the most well known of the implementations. ActionScript 3 is another well-known implementation of ECMAScript. In July of 2008 the disparate parties on either side came together in Oslo. This led to the eventual agreement in early 2009 to rename ECMAScript 3.1 to ECMAScript 5 and drive the language forward using an agenda that is known as Harmony. Current status: ECMA 6 draft is ready & published with pending approvals. http://people.mozilla.org/~jorendorff/es6-draft.html Compatibility: https://kangax.github.io/compat-table/es6/
  • 4. What is in ES6 ? Highlights: 1. Better syntax, more verbose. 2. Modules, AMD, Async Module Definition. 3. Developer friendly APIs. 4. Better code structuring. 5. Lesser effort/ number of lines than JS v5.
  • 5. A Bit of Deep Dive De-structuring – A new and flexible way to assign values from arrays or objects into variables. Array de-structuring var foo = ["one", "two"]; // without destructuring var one = foo[0]; var two = foo[1]; // with destructuring var [one, two] = foo; Object de-structuring var o = {p: 42, q: true}; var {p, q} = o; console.log(p); // 42 console.log(q); // true
  • 6. Block-level scope – ES6 now supports scoping variables to blocks (if, for, while, etc.) using the let keyword. Note: Variables declared by let have as their scope the block in which they are defined, as well as in any contained sub-blocks. In this way, let works very much like var. The main difference is that the scope of a var variable is the entire enclosing function. Eg: function varTest() { var x = 31; if (true) { var x = 71; // same variable! console.log(x); // 71 } console.log(x); // 71 } function letTest() { let x = 31; if (true) { let x = 71; // different variable console.log(x); // 71 } console.log(x); // 31 }
  • 7. Classes – ES6 classes provide a way to encapsulate and extend code. Note: ES6 has only added a syntactical change to this as a function in JavaScript behaves as a class. Eg: class Polygon { constructor(height, width) { this.height = height; this.width = width; } } Constants – You can now define constants in ES6 code using the const keyword. (This is already provided by Chrome since long) Eg: const my_fav = 7; Default parameters – Ever wished that a function parameter could be assigned a default value? You can do that now in ES6. Eg: function multiply(a, b = 1) { return a*b; } multiply(5); // 5
  • 8. Map – Dictionary type object that can be used to store key/value pairs. Note: We were using array’s associative property to serve as a map, but this had limitations like getting length & iteration was dependent on Object.keys Eg: var myMap = new Map(); myMap.set(“myKey”, “myValue”) myMap.get(“myKey”); // “myValue” Modules – Provides a modular way of organizing and loading code. The usage & module definition is on the lines of commonJS. Eg: //File module.js var someFunction(){ ….. } var myModule = function(){ return someFunction() } export myModule; //file client.js Import myModule from ‘module.js’ myModule();
  • 9. Promises – Used with asynchronous operations. Because async operations still have problems. Syntax: new Promise(function(resolve, reject) { ... }); Rest parameters – Replaces the need for using arguments to access functions arguments. Allows you to get to an array representing “the rest of the parameters”. Eg: function fun1(...theArgs) { console.log(theArgs.length); } fun1(); // 0 fun1(5); // 1 fun1(5, 6, 7); // 3
  • 10. Arrow functions – A short-hand version of writing an anonymous function. Syntax: ([param] [, param]) => { statements } param => expression Eg: var a2 = a.map(function(s){ return s.length }); Can be reduced to: var a3 = a.map( s => s.length ); Generators – Specialized functions that can be paused & restarted & can be used as iterators, declared using function* and the yield keyword. Note: Calling a generator function does not execute its body immediately; an iterator object for the function is returned instead. When the iterator's next() method is called, the generator function's body is executed until the first yield expression, which specifies the value to be returned from the iterator or, with yield*, delegates to another generator function. The next() method returns an object with a value property containing the yielded value and a done property which indicates whether the generator has yielded its last value Run..Stop..Run
  • 11. Syntax: function* name([param[, param[, ... param]]]) { statements yield value; } Name.next().value; Eg: function* idMaker(){ var index = 0; while(index < 3) yield index++; } var gen = idMaker(); console.log(gen.next().value); // 0 console.log(gen.next().value); // 1 console.log(gen.next().value); // 2 console.log(gen.next().value); // undefined ….
  • 12. Why Should We Bother ? 1. It is the future & we want to remain in the race. 2. Terminology & the language in which developers, websites, blogs, references etc talk, will change. 3. Most importantly : The libraries which we are currently depending on, are changing and adapting ES6 features. Our ground is going to shake, let’s be prepared. 4. Dependency on requireJS for AMD, Kriskowal’s q for Promises, Underscore for better Collection Processing etc will be gone
  • 13. Angular 2.0 1. Usage of classes. 2. Usage of modules. 3. Arrow functions. 4. Default parameters. 5. Rest parameters. 6. No controllers, scopes or directives Do watch : ES6 in Angular 2.0 by Erik Arvidsson at ng-europe 2014 https://www.youtube.com/watch?v=iij5RHKi66o And Angular 2.0 Core by Igor Minar & Tobias Bosch at ng-europe 2014 https://www.youtube.com/watch?v=gNmWybAyBHI