SlideShare a Scribd company logo
1 of 15
Download to read offline
The Lesser Known
Features of ECMAScript 6
Bryan Hughes, Ph.D.
@nebrius
Frontend Developer at Rdio
ECMAScript 6 is Coming
Here’s what I’m not talking about:
• Classes
• Modules
• Promises
• Generators
Block Scoped Variables
let your variables be more local:
if (true) {

let foo = 1;

const bar = 2;

console.log(foo, bar);

bar = 3; // Throws an exception

}

console.log(foo);
Prints:

1 2

Error: bar is read-only

Error: foo is undefined
Template Literals
Built-in string templating:
let foo = 'Bar';

console.log(`Hello "${foo}"`);
Prints:

Hello "Bar"
Computed Property Names
Dynamic property names in object literals:
let myProp = 'foo';

let myObj = {

[myProp]: 'bar'

}

console.log(myObj.foo);!
Prints:

bar
Shorthand Functions
Dynamic property names in object literals:
let myObj = {

foo() { console.log('bar'); }

}

myObj.foo();!
Prints:

bar
...rest Parameters
No More arguments:
myFunc(1, 2, 3, 4, 5);

function myFunc(a, b, ...rest) {

console.log(a, b);

console.log(Array.isArray(rest));

console.log(rest);

}
Prints:

1, 2

true

[3, 4, 5]
...spread Parameters
The opposite of …rest:
let myArray = [2, 3, 4];

myFunc(1, ...myArray);

function myFunc(a, b, c, d) {

console.log(a, b, c, d);

}
Prints:

1, 2, 3, 4
for...of Statements
Better* iteration over arrays:
let myArray = ['a', 'b', 'c'];

for (let myElement of myArray) {

console.log(myElement);

}
*not always better
Prints:

a

b

c
Destructuring Arrays
Something analogous to Python’s Tuples:
let myArray = [1, 2];

let [a, b] = myArray;

console.log(a, b);
Prints:

1 2
Destructuring Objects
Destructuring gets even better:
let myObj = {

one: 1,

two: 2

};

let { one: a, two: b } = myObj;

console.log(a, b);
Prints:

1 2
Mixing it Up
let a = 'first', b = 'last';

print({

[a](c) { return `${c ? "A" : "a"}lice`; },

[b](c) { return `${c ? "J" : "j"}ones`; }

}, {

[a](c) { return `${c ? "B" : "b"}ob`; },

[b](c) { return `${c ? "S" : "s"}mith`; }

});

function print(...people) {

for (let { first: a, last: b } of people) {

console.log(b(true) + ', ' + a(false));

}

}
Prints:

Jones, alice

Smith, bob
Mixing it Up, Oldschool
var a = 'first', b = 'last';

var myFirstObj = {};

myFirstObj[a] = function(c) { return (c ? 'A' : 'a') + ‘Alice'; };

myFirstObj[b] = function(c) { return (c ? 'J' : 'j') + ‘Jones'; };

var mySecondObj = {};

mySecondObj[a] = function(c) { return (c ? 'B' : 'b') + ‘Bob'; };

mySecondObj[b] = function(c) { return (c ? 'S' : 's') + ‘Smith'; };

print(myFirstObj, mySecondObj);

function print() {

var args = Array.prototype.slice.apply(arguments);

args.forEach(function(arg) {

var a = arg.first;

var b = arg.last;

console.log(b(true) + ', ' + a(false));

});

}
Slides:

slidesha.re/1nFBm5D 

Code:

bit.ly/1nFBGl1
Bryan Hughes
@nebrius
Further Reading
• Human Readable Wiki: http://
wiki.ecmascript.org/doku.php?
id=harmony:proposals
• Formal Spec: http://wiki.ecmascript.org/
doku.php?id=harmony:specification_drafts
• Traceur Compiler: https://github.com/google/
traceur-compiler/wiki/GettingStarted

More Related Content

What's hot

Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages Today
Refresh Events
 
Как показать 90 млн картинок и сохранить жизнь диску
Как показать 90 млн картинок и сохранить жизнь дискуКак показать 90 млн картинок и сохранить жизнь диску
Как показать 90 млн картинок и сохранить жизнь диску
CEE-SEC(R)
 
completion_proc and history
completion_proc and historycompletion_proc and history
completion_proc and history
Nobuhiro IMAI
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
niklal
 

What's hot (20)

Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages Today
 
Как показать 90 млн картинок и сохранить жизнь диску
Как показать 90 млн картинок и сохранить жизнь дискуКак показать 90 млн картинок и сохранить жизнь диску
Как показать 90 млн картинок и сохранить жизнь диску
 
Как показать 90 млн картинок и сохранить жизнь диску
Как показать 90 млн картинок и сохранить жизнь дискуКак показать 90 млн картинок и сохранить жизнь диску
Как показать 90 млн картинок и сохранить жизнь диску
 
Javascript - The basics
Javascript - The basicsJavascript - The basics
Javascript - The basics
 
Shell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbaiShell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbai
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
Rakudo
RakudoRakudo
Rakudo
 
Zsh shell-for-humans
Zsh shell-for-humansZsh shell-for-humans
Zsh shell-for-humans
 
Why Kotlin is your next language?
Why Kotlin is your next language? Why Kotlin is your next language?
Why Kotlin is your next language?
 
Let's fly to the Kotlin Island. Just an introduction to Kotlin
Let's fly to the Kotlin Island. Just an introduction to KotlinLet's fly to the Kotlin Island. Just an introduction to Kotlin
Let's fly to the Kotlin Island. Just an introduction to Kotlin
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
 
JavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher ChedeauJavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher Chedeau
 
Javascript 101 - Javascript para Iniciantes
Javascript 101 - Javascript para IniciantesJavascript 101 - Javascript para Iniciantes
Javascript 101 - Javascript para Iniciantes
 
Debug like a doctor
Debug like a doctorDebug like a doctor
Debug like a doctor
 
Golang勉強会
Golang勉強会Golang勉強会
Golang勉強会
 
completion_proc and history
completion_proc and historycompletion_proc and history
completion_proc and history
 
TDDBC お題
TDDBC お題TDDBC お題
TDDBC お題
 
Txjs
TxjsTxjs
Txjs
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
 
Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''
 

Similar to The Lesser Known Features of ECMAScript 6

js+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfjs+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdf
NuttavutThongjor1
 

Similar to The Lesser Known Features of ECMAScript 6 (20)

ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
ts+js
ts+jsts+js
ts+js
 
js+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfjs+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdf
 
fullstack typescript with react and express.pdf
fullstack typescript with react and express.pdffullstack typescript with react and express.pdf
fullstack typescript with react and express.pdf
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
 
recap-js-and-ts.pdf
recap-js-and-ts.pdfrecap-js-and-ts.pdf
recap-js-and-ts.pdf
 
Realm: Building a mobile database
Realm: Building a mobile databaseRealm: Building a mobile database
Realm: Building a mobile database
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
 
サイ本 文
サイ本 文サイ本 文
サイ本 文
 
Coffee script
Coffee scriptCoffee script
Coffee script
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
Defcon 23 - Daniel Selifonov - drinking from LETHE
Defcon 23 - Daniel Selifonov - drinking from LETHEDefcon 23 - Daniel Selifonov - drinking from LETHE
Defcon 23 - Daniel Selifonov - drinking from LETHE
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
 
CS50 Lecture3
CS50 Lecture3CS50 Lecture3
CS50 Lecture3
 
ES6: The future is now
ES6: The future is nowES6: The future is now
ES6: The future is now
 
recap-js.pdf
recap-js.pdfrecap-js.pdf
recap-js.pdf
 
Python crush course
Python crush coursePython crush course
Python crush course
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 

More from Bryan Hughes

More from Bryan Hughes (6)

The Node.js Event Loop: Not So Single Threaded
The Node.js Event Loop: Not So Single ThreadedThe Node.js Event Loop: Not So Single Threaded
The Node.js Event Loop: Not So Single Threaded
 
Effective Documentation for Open Source Projects (Open Source 101 Version)
Effective Documentation for Open Source Projects (Open Source 101 Version) Effective Documentation for Open Source Projects (Open Source 101 Version)
Effective Documentation for Open Source Projects (Open Source 101 Version)
 
Effective Documentation for Open Source Projects (SFNode Version)
Effective Documentation for Open Source Projects (SFNode Version)Effective Documentation for Open Source Projects (SFNode Version)
Effective Documentation for Open Source Projects (SFNode Version)
 
Effective Documentation for Open Source Projects
Effective Documentation for Open Source ProjectsEffective Documentation for Open Source Projects
Effective Documentation for Open Source Projects
 
Johnny five
Johnny fiveJohnny five
Johnny five
 
So You Want to Build a Circuit
So You Want to Build a CircuitSo You Want to Build a Circuit
So You Want to Build a Circuit
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

The Lesser Known Features of ECMAScript 6

  • 1. The Lesser Known Features of ECMAScript 6 Bryan Hughes, Ph.D. @nebrius Frontend Developer at Rdio
  • 2. ECMAScript 6 is Coming Here’s what I’m not talking about: • Classes • Modules • Promises • Generators
  • 3. Block Scoped Variables let your variables be more local: if (true) {
 let foo = 1;
 const bar = 2;
 console.log(foo, bar);
 bar = 3; // Throws an exception
 }
 console.log(foo); Prints:
 1 2
 Error: bar is read-only
 Error: foo is undefined
  • 4. Template Literals Built-in string templating: let foo = 'Bar';
 console.log(`Hello "${foo}"`); Prints:
 Hello "Bar"
  • 5. Computed Property Names Dynamic property names in object literals: let myProp = 'foo';
 let myObj = {
 [myProp]: 'bar'
 }
 console.log(myObj.foo);! Prints:
 bar
  • 6. Shorthand Functions Dynamic property names in object literals: let myObj = {
 foo() { console.log('bar'); }
 }
 myObj.foo();! Prints:
 bar
  • 7. ...rest Parameters No More arguments: myFunc(1, 2, 3, 4, 5);
 function myFunc(a, b, ...rest) {
 console.log(a, b);
 console.log(Array.isArray(rest));
 console.log(rest);
 } Prints:
 1, 2
 true
 [3, 4, 5]
  • 8. ...spread Parameters The opposite of …rest: let myArray = [2, 3, 4];
 myFunc(1, ...myArray);
 function myFunc(a, b, c, d) {
 console.log(a, b, c, d);
 } Prints:
 1, 2, 3, 4
  • 9. for...of Statements Better* iteration over arrays: let myArray = ['a', 'b', 'c'];
 for (let myElement of myArray) {
 console.log(myElement);
 } *not always better Prints:
 a
 b
 c
  • 10. Destructuring Arrays Something analogous to Python’s Tuples: let myArray = [1, 2];
 let [a, b] = myArray;
 console.log(a, b); Prints:
 1 2
  • 11. Destructuring Objects Destructuring gets even better: let myObj = {
 one: 1,
 two: 2
 };
 let { one: a, two: b } = myObj;
 console.log(a, b); Prints:
 1 2
  • 12. Mixing it Up let a = 'first', b = 'last';
 print({
 [a](c) { return `${c ? "A" : "a"}lice`; },
 [b](c) { return `${c ? "J" : "j"}ones`; }
 }, {
 [a](c) { return `${c ? "B" : "b"}ob`; },
 [b](c) { return `${c ? "S" : "s"}mith`; }
 });
 function print(...people) {
 for (let { first: a, last: b } of people) {
 console.log(b(true) + ', ' + a(false));
 }
 } Prints:
 Jones, alice
 Smith, bob
  • 13. Mixing it Up, Oldschool var a = 'first', b = 'last';
 var myFirstObj = {};
 myFirstObj[a] = function(c) { return (c ? 'A' : 'a') + ‘Alice'; };
 myFirstObj[b] = function(c) { return (c ? 'J' : 'j') + ‘Jones'; };
 var mySecondObj = {};
 mySecondObj[a] = function(c) { return (c ? 'B' : 'b') + ‘Bob'; };
 mySecondObj[b] = function(c) { return (c ? 'S' : 's') + ‘Smith'; };
 print(myFirstObj, mySecondObj);
 function print() {
 var args = Array.prototype.slice.apply(arguments);
 args.forEach(function(arg) {
 var a = arg.first;
 var b = arg.last;
 console.log(b(true) + ', ' + a(false));
 });
 }
  • 15. Further Reading • Human Readable Wiki: http:// wiki.ecmascript.org/doku.php? id=harmony:proposals • Formal Spec: http://wiki.ecmascript.org/ doku.php?id=harmony:specification_drafts • Traceur Compiler: https://github.com/google/ traceur-compiler/wiki/GettingStarted

Editor's Notes

  1. Check them out at http://wiki.ecmascript.org/doku.php?id=harmony:proposals
  2. Wiki: http://wiki.ecmascript.org/doku.php?id=harmony:object_literals#object_literal_computed_property_keys
  3. Wiki: http://wiki.ecmascript.org/doku.php?id=harmony:object_literals#object_literal_property_shorthands
  4. Wiki: http://wiki.ecmascript.org/doku.php?id=harmony:rest_parameters
  5. Wiki: http://wiki.ecmascript.org/doku.php?id=harmony:spread
  6. Wiki: http://wiki.ecmascript.org/doku.php?id=harmony:iterators
  7. Wiki: http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
  8. Wiki: http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
  9. Read more at: http://wiki.ecmascript.org/doku.php?id=harmony:proposals http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts To play with ECMAScript 6, try Traceur: https://github.com/google/traceur-compiler/wiki/GettingStarted All code snippets from this talk are available in a packaged Traceur web page at: https://gitlab.theoreticalideations.com/snippets/2