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 TodayRefresh Events
 
Как показать 90 млн картинок и сохранить жизнь диску
Как показать 90 млн картинок и сохранить жизнь дискуКак показать 90 млн картинок и сохранить жизнь диску
Как показать 90 млн картинок и сохранить жизнь дискуCEE-SEC(R)
 
Как показать 90 млн картинок и сохранить жизнь диску
Как показать 90 млн картинок и сохранить жизнь дискуКак показать 90 млн картинок и сохранить жизнь диску
Как показать 90 млн картинок и сохранить жизнь дискуАндрей Шорин
 
Javascript - The basics
Javascript - The basicsJavascript - The basics
Javascript - The basicsBruno Paulino
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges✅ William Pinaud
 
Zsh shell-for-humans
Zsh shell-for-humansZsh shell-for-humans
Zsh shell-for-humansJuan De Bravo
 
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 KotlinAliaksei Zhynhiarouski
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in goYusuke Kita
 
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 ChedeauReact London 2017
 
Javascript 101 - Javascript para Iniciantes
Javascript 101 - Javascript para IniciantesJavascript 101 - Javascript para Iniciantes
Javascript 101 - Javascript para IniciantesGabrielSchiavo1
 
completion_proc and history
completion_proc and historycompletion_proc and history
completion_proc and historyNobuhiro IMAI
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsagniklal
 
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''OdessaJS Conf
 

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 ECMAScript 6 Features for Better JavaScript Code

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.pdfNuttavutThongjor1
 
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.pdfNuttavutThongjor1
 
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 ScalaPhilip Schwarz
 
Realm: Building a mobile database
Realm: Building a mobile databaseRealm: Building a mobile database
Realm: Building a mobile databaseChristian Melchior
 
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) ThingsMichael Pirnat
 
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 LETHEFelipe Prado
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival GuideGiordano Scalzo
 
CS50 Lecture3
CS50 Lecture3CS50 Lecture3
CS50 Lecture3昀 李
 
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!Paige Bailey
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervosoLuis Vendrame
 

Similar to ECMAScript 6 Features for Better JavaScript Code (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

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 ThreadedBryan Hughes
 
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) Bryan Hughes
 
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)Bryan Hughes
 
Effective Documentation for Open Source Projects
Effective Documentation for Open Source ProjectsEffective Documentation for Open Source Projects
Effective Documentation for Open Source ProjectsBryan Hughes
 
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 CircuitBryan 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

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Recently uploaded (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

ECMAScript 6 Features for Better JavaScript Code

  • 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