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

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
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
 
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
 
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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
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
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
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
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
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
 

Recently uploaded (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
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)
 
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
 
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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
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
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
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
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
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
 

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