SlideShare a Scribd company logo
JS
JSJavaScripters
JavaScripters community Initiative
http://www.javascripters.org
Saturday, 19 Dec 2015
TypeScript & ES6
Fundamentals
JS
JSJavaScripters
About Speakers
Imran Shaikh
Senior Front-end Engineer & HFI certified Usability Analyst
Around 11 years of experience
Author, Speaker & co-founder of JavaScripters community
Website: http://shaikh-imran.com
LinkedIn-profile: https://www.linkedin.com/in/shaikhimran786
Avinash Jha
Senior Front-end Engineer
Around 5 years of experience
JS
JSJavaScripters
Agenda
• TypeScript & ES6 Fundamentals
• Javascript History
• ES6 introduction
• Assignment De-structuring
• Set default parameter values
• Use variable args without the arguments object
• Define a function quicker than you can type “function () {}”
• Create variables with block scope
• Create and manipulate Sets
• Template Literals
• Object Literals
JS
JSJavaScripters
JavaScript History
• Invented at Netscape by Brendan Eich
• Mocha -> LiveScript -> JavaScript
•1996 -> Standardization taken by Ecma
• Renamed -> ECMAScript (trademark reasons)
•ECMAScript -> Spec
•JavaScript -> Implementation of ES
•ES6 -> Version of ES (old style)
•ES2015 -> Version of ES (new style)
•ES Harmony -> TC39’s wish list
•ES.Next -> Next version alias
JS
JSJavaScripters
ES6 Introduction
•ES6 – also known as Harmony, es-next, ES2015 – is the latest finalized specification of
the language
•The ES6 specification was finalized in June 2015, (hence ES2015)
•Future versions of the specification will follow the ES[YYYY] pattern, e.g ES2016 for ES7
•Yearly release schedule, features that don’t make the cut take the next train
•Since ES6 pre-dates that decision, most of us still call it ES6
•Starting with ES2016 (ES7), we should start using the ES[YYYY] pattern to refer to
newer versions
•Top reason for naming scheme is to pressure browser vendors into quickly implementing
newest features
JS
JSJavaScripters
ES6 isn’t fully in browser yet
…..right?
JS
JSJavaScripters
But
Transpilers to the rescue! 
What is Transpiler?
It simply take feature syntax and transpile it to today JS(ES5)
https://babeljs.io/
JS
JSJavaScripters
Assignment De-structuring
• Extract the weekday, month, date and year from Date() in one fell swoop:
var [day, month, date, year] = Date().split(' ');
•Using destructured assignment, you can extract multiple fields from an array and assign them to a
set of variables. It doesn’t quite work for objects yet, but arrays work fine.
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
JS
JSJavaScripters
Set default parameter values
Example :
let f = function(x, y=1) {console.log(x,y)};
f(22); // 22 1
•Finally, we can get rid of the various (sometimes dubious) default parameter patterns, with built-in
support for default parameters. Once destructured object assignments are complete, we’ll be able
to use those for setting defaults from named parameter objects as well.
JS
JSJavaScripters
Use variable args without the arguments object
Example:
let f = function(x,y,z, ...a) { console.log(a) }
f(1,2,3,7,8,9,'a','b','c'); // 7 8 9 'a' 'b' 'c’
•One word of wisdom I often see is that the arguments object is not an array, and you should not
treat it like one. With the rest operator, you don’t need the arguments object, and the rest of the
parameters really do end up in a real array.
JS
JSJavaScripters
Define a function quicker than you can type “function () {}”:
Example:
let f = (x) => x*x
•For a language that is arguably functional at heart, Javascript picked an unusually verbose
keyword to describe functions, especially given the prevalence of callback routines and object
methods which involve an awful lot of repetition of the word “function”. And while not everyone loves
CoffeeScript, I suspect even the haters are sometimes jealous of its arrow notation as a shortcut to
describe functions. The fat arrow knocks out two birds with one stone, as it also provides a
lexical this pointer, the lack of which confuses many a new Javascript programmer.
JS
JSJavaScripters
Create variables with block scope:
let f = function () {
let n=1;
for (let n=5,i=0; i<n; i++) {
console.log(i);
}
console.log(n);
};
f(); // 0 1 2 3 4 1
•Perhaps the most anticipated feature of Ecmascript 6 is the arrival of Block Scoping. One of the
single biggest drawbacks of Javascript is its scoping, especially the lack of block scoping, leading to
common anti-patterns like declaring every single local variable at the top of a function, regardless of
where it’s used. With the new let statement we finally have variables with lifetimes that last only until
the end of the block.
JS
JSJavaScripters
Create and manipulate Sets:
let s = new Set();
[2,3,5,4,5,2,2].map(x => s.add(x))
for (let i of s) {console.log(i)} // 2 3 4 5
•There’s a reason that mathematicians invented sets, and sometimes developers need them too.
Now instead of needing to implement them or rely on another JS library, they’re just there.
JS
JSJavaScripters
Template Literals
•You can declare strings with ` (backticks), in addition to " and '
•Strings wrapped in backticks are template literals
•Template literals can be multiline
•Template literals allow interpolation like `ponyfoo.com is ${rating}` where rating is a variable
•You can use any valid JavaScript expressions in the interpolation, such as `${2 * 3}` or `${foo()}`
•Add a fn prefix to fn`foo, ${bar} and ${baz}`
•fn is called once with template, ...expressions
•template is ['foo, ', ' and ', ''] and expressions is [bar, baz]
JS
JSJavaScripters
Object Literals
•Instead of { foo: foo }, you can just do { foo } – known as a property value shorthand
•Computed property names, { [prefix + 'Foo']: 'bar' }, where prefix: 'moz', yields { mozFoo: 'bar' }
•You can’t combine computed property names and property value shorthands, { [foo] } is invalid
•Method definitions in an object literal can be declared using an alternative,
more terse syntax, { foo () {}
JS
JSJavaScripters
Transpiler ES5 code into ES6
Good News Now we have ES5 to ES6
http://xto6.js.org/ 
JS
JSJavaScripters
References
• https://leanpub.com/understandinges6/
• http://es6-features.org/
• http://www.es6fiddle.com/
• https://ponyfoo.com/articles/es6
Breaking News
•http://microsoft-news.com/microsoft-and-google-collaborated-on-making-typescript-more-awesome/

More Related Content

What's hot

Squeak DBX
Squeak DBXSqueak DBX
Squeak DBX
ESUG
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6
Nilesh Jayanandana
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORP
ESUG
 
Cassandra and materialized views
Cassandra and materialized viewsCassandra and materialized views
Cassandra and materialized views
Grzegorz Duda
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
Stuart Roebuck
 
AkJS Meetup - ES6++
AkJS Meetup -  ES6++AkJS Meetup -  ES6++
AkJS Meetup - ES6++
Isaac Johnston
 
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing EraECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
Allen Wirfs-Brock
 
DSLs Internas e Ruby
DSLs Internas e RubyDSLs Internas e Ruby
DSLs Internas e Ruby
Fabio Kung
 
JS Essence
JS EssenceJS Essence
JS Essence
Uladzimir Piatryka
 
XQuery Rocks
XQuery RocksXQuery Rocks
XQuery Rocks
William Candillon
 
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPDoctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Guilherme Blanco
 
Scala Macros
Scala MacrosScala Macros
Scala Macros
Adam Warski
 
Cassandra UDF and Materialized Views
Cassandra UDF and Materialized ViewsCassandra UDF and Materialized Views
Cassandra UDF and Materialized Views
Duyhai Doan
 
Lobos Introduction
Lobos IntroductionLobos Introduction
Lobos Introduction
Nicolas Buduroi
 
Building data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyBuilding data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemy
Roger Barnes
 
Not your Grandma's XQuery
Not your Grandma's XQueryNot your Grandma's XQuery
Not your Grandma's XQuery
William Candillon
 
Drupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsDrupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First Steps
Luís Carneiro
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
pratiknaik
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
Chris Adamson
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
Solution4Future
 

What's hot (20)

Squeak DBX
Squeak DBXSqueak DBX
Squeak DBX
 
Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6Introduction to Ecmascript - ES6
Introduction to Ecmascript - ES6
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORP
 
Cassandra and materialized views
Cassandra and materialized viewsCassandra and materialized views
Cassandra and materialized views
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
AkJS Meetup - ES6++
AkJS Meetup -  ES6++AkJS Meetup -  ES6++
AkJS Meetup - ES6++
 
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing EraECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
 
DSLs Internas e Ruby
DSLs Internas e RubyDSLs Internas e Ruby
DSLs Internas e Ruby
 
JS Essence
JS EssenceJS Essence
JS Essence
 
XQuery Rocks
XQuery RocksXQuery Rocks
XQuery Rocks
 
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHPDoctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
 
Scala Macros
Scala MacrosScala Macros
Scala Macros
 
Cassandra UDF and Materialized Views
Cassandra UDF and Materialized ViewsCassandra UDF and Materialized Views
Cassandra UDF and Materialized Views
 
Lobos Introduction
Lobos IntroductionLobos Introduction
Lobos Introduction
 
Building data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyBuilding data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemy
 
Not your Grandma's XQuery
Not your Grandma's XQueryNot your Grandma's XQuery
Not your Grandma's XQuery
 
Drupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First StepsDrupal Camp Porto - Developing with Drupal: First Steps
Drupal Camp Porto - Developing with Drupal: First Steps
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 

Viewers also liked

Mb0051 fall drive assignment-2012-1
Mb0051 fall drive assignment-2012-1Mb0051 fall drive assignment-2012-1
Mb0051 fall drive assignment-2012-1
anil521152591
 
Symmetry
SymmetrySymmetry
Symmetry
yadugopan
 
Prueba admision2007 2
Prueba admision2007 2Prueba admision2007 2
Prueba admision2007 2
pasaralau
 
Prueba admision2008 1
Prueba admision2008 1Prueba admision2008 1
Prueba admision2008 1
pasaralau
 
Exponents and powers
Exponents and powersExponents and powers
Exponents and powers
yadugopan
 
oojs
oojsoojs
Internet
InternetInternet
Internet
salmahaliuma
 
Prueba admision2004 2
Prueba admision2004 2Prueba admision2004 2
Prueba admision2004 2
pasaralau
 
Influence of inceptisol and alfisol’s Potassium Solubilizing Bacteria (KSB) i...
Influence of inceptisol and alfisol’s Potassium Solubilizing Bacteria (KSB) i...Influence of inceptisol and alfisol’s Potassium Solubilizing Bacteria (KSB) i...
Influence of inceptisol and alfisol’s Potassium Solubilizing Bacteria (KSB) i...
Vijay Singh Meena
 
Headcount new (3)
Headcount new (3)Headcount new (3)
Headcount new (3)
Juliana Muhd Tajuddin
 
Ppt.maths angles 1
Ppt.maths angles 1Ppt.maths angles 1
Ppt.maths angles 1
yadugopan
 
баримт бичгийн-бүрдүүлэлт
баримт бичгийн-бүрдүүлэлтбаримт бичгийн-бүрдүүлэлт
баримт бичгийн-бүрдүүлэлт
Jargalsaikhan Battulga
 
Site analysis for a neighborhood
Site analysis for a neighborhoodSite analysis for a neighborhood
Site analysis for a neighborhood
Ajit Katari
 
Ajit katari book review
Ajit katari book reviewAjit katari book review
Ajit katari book review
Ajit Katari
 
Fractions
FractionsFractions
Fractions
yadugopan
 

Viewers also liked (15)

Mb0051 fall drive assignment-2012-1
Mb0051 fall drive assignment-2012-1Mb0051 fall drive assignment-2012-1
Mb0051 fall drive assignment-2012-1
 
Symmetry
SymmetrySymmetry
Symmetry
 
Prueba admision2007 2
Prueba admision2007 2Prueba admision2007 2
Prueba admision2007 2
 
Prueba admision2008 1
Prueba admision2008 1Prueba admision2008 1
Prueba admision2008 1
 
Exponents and powers
Exponents and powersExponents and powers
Exponents and powers
 
oojs
oojsoojs
oojs
 
Internet
InternetInternet
Internet
 
Prueba admision2004 2
Prueba admision2004 2Prueba admision2004 2
Prueba admision2004 2
 
Influence of inceptisol and alfisol’s Potassium Solubilizing Bacteria (KSB) i...
Influence of inceptisol and alfisol’s Potassium Solubilizing Bacteria (KSB) i...Influence of inceptisol and alfisol’s Potassium Solubilizing Bacteria (KSB) i...
Influence of inceptisol and alfisol’s Potassium Solubilizing Bacteria (KSB) i...
 
Headcount new (3)
Headcount new (3)Headcount new (3)
Headcount new (3)
 
Ppt.maths angles 1
Ppt.maths angles 1Ppt.maths angles 1
Ppt.maths angles 1
 
баримт бичгийн-бүрдүүлэлт
баримт бичгийн-бүрдүүлэлтбаримт бичгийн-бүрдүүлэлт
баримт бичгийн-бүрдүүлэлт
 
Site analysis for a neighborhood
Site analysis for a neighborhoodSite analysis for a neighborhood
Site analysis for a neighborhood
 
Ajit katari book review
Ajit katari book reviewAjit katari book review
Ajit katari book review
 
Fractions
FractionsFractions
Fractions
 

Similar to es6

React Native Evening
React Native EveningReact Native Evening
React Native Evening
Troy Miles
 
ECMAScript: past, present and future
ECMAScript: past, present and futureECMAScript: past, present and future
ECMAScript: past, present and future
Kseniya Redunova
 
Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !
Gaurav Behere
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson
 
Intro to React
Intro to ReactIntro to React
Intro to React
Troy Miles
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Codemotion
 
Java Script
Java ScriptJava Script
Java Script
Sarvan15
 
Java Script
Java ScriptJava Script
Java Script
Sarvan15
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
Alex Payne
 
JavaScript-Core
JavaScript-CoreJavaScript-Core
JavaScript-Core
tutorialsruby
 
JavaScript-Core
JavaScript-CoreJavaScript-Core
JavaScript-Core
tutorialsruby
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Marlon Jamera
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
SreeVani74
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
Codemotion
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
Eduard Tomàs
 
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in PracticeOpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
Jesse Gallagher
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
Ramnivas Laddad
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
sentayehu
 

Similar to es6 (20)

React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
ECMAScript: past, present and future
ECMAScript: past, present and futureECMAScript: past, present and future
ECMAScript: past, present and future
 
Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
Java Script
Java ScriptJava Script
Java Script
 
Java Script
Java ScriptJava Script
Java Script
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
JavaScript-Core
JavaScript-CoreJavaScript-Core
JavaScript-Core
 
JavaScript-Core
JavaScript-CoreJavaScript-Core
JavaScript-Core
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in PracticeOpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
OpenNTF Webinar 2022-08 - XPages Jakarta EE Support in Practice
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
 
javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
 

es6

  • 2. JS JSJavaScripters About Speakers Imran Shaikh Senior Front-end Engineer & HFI certified Usability Analyst Around 11 years of experience Author, Speaker & co-founder of JavaScripters community Website: http://shaikh-imran.com LinkedIn-profile: https://www.linkedin.com/in/shaikhimran786 Avinash Jha Senior Front-end Engineer Around 5 years of experience
  • 3. JS JSJavaScripters Agenda • TypeScript & ES6 Fundamentals • Javascript History • ES6 introduction • Assignment De-structuring • Set default parameter values • Use variable args without the arguments object • Define a function quicker than you can type “function () {}” • Create variables with block scope • Create and manipulate Sets • Template Literals • Object Literals
  • 4. JS JSJavaScripters JavaScript History • Invented at Netscape by Brendan Eich • Mocha -> LiveScript -> JavaScript •1996 -> Standardization taken by Ecma • Renamed -> ECMAScript (trademark reasons) •ECMAScript -> Spec •JavaScript -> Implementation of ES •ES6 -> Version of ES (old style) •ES2015 -> Version of ES (new style) •ES Harmony -> TC39’s wish list •ES.Next -> Next version alias
  • 5. JS JSJavaScripters ES6 Introduction •ES6 – also known as Harmony, es-next, ES2015 – is the latest finalized specification of the language •The ES6 specification was finalized in June 2015, (hence ES2015) •Future versions of the specification will follow the ES[YYYY] pattern, e.g ES2016 for ES7 •Yearly release schedule, features that don’t make the cut take the next train •Since ES6 pre-dates that decision, most of us still call it ES6 •Starting with ES2016 (ES7), we should start using the ES[YYYY] pattern to refer to newer versions •Top reason for naming scheme is to pressure browser vendors into quickly implementing newest features
  • 6. JS JSJavaScripters ES6 isn’t fully in browser yet …..right?
  • 7. JS JSJavaScripters But Transpilers to the rescue!  What is Transpiler? It simply take feature syntax and transpile it to today JS(ES5) https://babeljs.io/
  • 8. JS JSJavaScripters Assignment De-structuring • Extract the weekday, month, date and year from Date() in one fell swoop: var [day, month, date, year] = Date().split(' '); •Using destructured assignment, you can extract multiple fields from an array and assign them to a set of variables. It doesn’t quite work for objects yet, but arrays work fine. 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
  • 9. JS JSJavaScripters Set default parameter values Example : let f = function(x, y=1) {console.log(x,y)}; f(22); // 22 1 •Finally, we can get rid of the various (sometimes dubious) default parameter patterns, with built-in support for default parameters. Once destructured object assignments are complete, we’ll be able to use those for setting defaults from named parameter objects as well.
  • 10. JS JSJavaScripters Use variable args without the arguments object Example: let f = function(x,y,z, ...a) { console.log(a) } f(1,2,3,7,8,9,'a','b','c'); // 7 8 9 'a' 'b' 'c’ •One word of wisdom I often see is that the arguments object is not an array, and you should not treat it like one. With the rest operator, you don’t need the arguments object, and the rest of the parameters really do end up in a real array.
  • 11. JS JSJavaScripters Define a function quicker than you can type “function () {}”: Example: let f = (x) => x*x •For a language that is arguably functional at heart, Javascript picked an unusually verbose keyword to describe functions, especially given the prevalence of callback routines and object methods which involve an awful lot of repetition of the word “function”. And while not everyone loves CoffeeScript, I suspect even the haters are sometimes jealous of its arrow notation as a shortcut to describe functions. The fat arrow knocks out two birds with one stone, as it also provides a lexical this pointer, the lack of which confuses many a new Javascript programmer.
  • 12. JS JSJavaScripters Create variables with block scope: let f = function () { let n=1; for (let n=5,i=0; i<n; i++) { console.log(i); } console.log(n); }; f(); // 0 1 2 3 4 1 •Perhaps the most anticipated feature of Ecmascript 6 is the arrival of Block Scoping. One of the single biggest drawbacks of Javascript is its scoping, especially the lack of block scoping, leading to common anti-patterns like declaring every single local variable at the top of a function, regardless of where it’s used. With the new let statement we finally have variables with lifetimes that last only until the end of the block.
  • 13. JS JSJavaScripters Create and manipulate Sets: let s = new Set(); [2,3,5,4,5,2,2].map(x => s.add(x)) for (let i of s) {console.log(i)} // 2 3 4 5 •There’s a reason that mathematicians invented sets, and sometimes developers need them too. Now instead of needing to implement them or rely on another JS library, they’re just there.
  • 14. JS JSJavaScripters Template Literals •You can declare strings with ` (backticks), in addition to " and ' •Strings wrapped in backticks are template literals •Template literals can be multiline •Template literals allow interpolation like `ponyfoo.com is ${rating}` where rating is a variable •You can use any valid JavaScript expressions in the interpolation, such as `${2 * 3}` or `${foo()}` •Add a fn prefix to fn`foo, ${bar} and ${baz}` •fn is called once with template, ...expressions •template is ['foo, ', ' and ', ''] and expressions is [bar, baz]
  • 15. JS JSJavaScripters Object Literals •Instead of { foo: foo }, you can just do { foo } – known as a property value shorthand •Computed property names, { [prefix + 'Foo']: 'bar' }, where prefix: 'moz', yields { mozFoo: 'bar' } •You can’t combine computed property names and property value shorthands, { [foo] } is invalid •Method definitions in an object literal can be declared using an alternative, more terse syntax, { foo () {}
  • 16. JS JSJavaScripters Transpiler ES5 code into ES6 Good News Now we have ES5 to ES6 http://xto6.js.org/ 
  • 17. JS JSJavaScripters References • https://leanpub.com/understandinges6/ • http://es6-features.org/ • http://www.es6fiddle.com/ • https://ponyfoo.com/articles/es6 Breaking News •http://microsoft-news.com/microsoft-and-google-collaborated-on-making-typescript-more-awesome/