SlideShare a Scribd company logo
ES6 JavaScript
Rob Lund
Classes
class Panel {
constructor() {
// make the thing
}
addItem(toAdd) {
// add the item
}
}
Arrow Functions
arrayOfSomeStuff.filter(item => item < 20)
toggle.addEventListener('click', (evt) => {
// toggle the toggle
})
this
class Layer {
this.url = 'http://onxmaps.com/'
..
pages.forEach(function(page) {
console.log(this.url + page)
}.bind(this))
}
class Layer {
this.url = 'http://onxmaps.com/'
..
pages.forEach((page) => {
console.log(this.url + page)
})
}
Objects
var preferences = {
fontSize: 16,
// shorthand for theme: theme
theme
}
* there are a couple other object literal changes that have
varying levels of support and usefulness.
Template Strings
`using the backticks`
`now supports
multiline
strings`
`added ${adjective} support for interpolation`
Destructuring
var [name, type] = ['rob', 'shoe']
var {label, activity} = getActivity()
var [title, , link] = ['señor', 'rob', 'http://...']
function findAccount({name: customerName}) {
console.log(customerName)
}
Parameter Handling
// defaults
function getBook(title, version = 1) { .. }
// rest or splat operator
function addShoes(color, ...attributes) {
// attributes is an array containing parameters 2+
attributes.forEach(..)
}
// spread operator
function removeItem(name, type, element) { .. }
removeItem(...['walrus', 'shoe', panelElement])
// spread can also be used in other areas, like
// array or object literals (eg. simple concat)
var allLayers = [layer1, layer2, ...everythingElse]
const & let
// block-scoped read only values
const name = 'walrus'
// block-scoped variable values
let uri = '/account/'
Do not become part of the window object like var
for..of loops
for (const item of pileOfItems) {
console.log(item)
}
The problem with the old for..in loops:
• Did weird things with objects (nested properties)
• Did weird things with arrays (out of order)
New for..of loops:
• Flat out don't work with objects (stop iterating over object
properties you animal)
• Works great with arrays
* caveat: for..of works with iterable collections like NodeList, but
IE/Edge still has a rough time with this.
Modules
export function addItem(toAdd) { .. }
export const scale = 12
export class Layer { .. }
..
import { addItem, scale, Layer } from 'lib/layer'
// import everything with *
import * as layerLib from 'lib/layer'
console.log(layerLib.scale)
// default export
export default class Layer { .. }
..
import LayerHelper from 'lib/layer'
Promises
fetch(this.environment.apiUrl + '/v1/preferences', options)
.then(checkStatus)
.then(parseJson)
.then((response) => {
// do something with our parsed response object
})
.catch((error) => {
// handle your error
})
Writing your asynchronous code in a synchronous fashion
Other
• Map, Set data structures
• New helpful Math APIs
• Unicode variables and matching
• Generators
Thanks.
(Happy Valentine's Day)

More Related Content

KEY
Underscore.js
PDF
Introduction to Underscore.js
PPTX
Introduction to Underscore.js
PDF
Memory Management on iOS
PDF
Monads in javascript
PDF
Introduction to Ember
PDF
What's new in iOS9
PDF
From android/ java to swift (2)
Underscore.js
Introduction to Underscore.js
Introduction to Underscore.js
Memory Management on iOS
Monads in javascript
Introduction to Ember
What's new in iOS9
From android/ java to swift (2)

What's hot (20)

PDF
Developing iOS REST Applications
PPTX
Iniciando com jquery
PPT
Memory management in Objective C
PPTX
Creating sub zero dashboard plugin for apex with google
PDF
Chainable datasource
PPTX
Angular 2 Architecture
PPTX
Mobile TechTalk - Interesting talks from NSConference 6
ODP
JavaScript Web Development
PDF
Tweaking the interactive grid
ZIP
iOS Memory Management Basics
PPTX
Frontend application architecture, patterns, and workflows
PDF
Backbone intro
PPTX
jQuery basics for Beginners
PPT
Objective C Memory Management
PDF
はじめてのUnitTest XCTestに触れて
PPTX
iOS Beginners Lesson 4
PPT
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
PDF
Swift Ready for Production?
PDF
Realm database
PDF
Introduction to meta-programming in scala
Developing iOS REST Applications
Iniciando com jquery
Memory management in Objective C
Creating sub zero dashboard plugin for apex with google
Chainable datasource
Angular 2 Architecture
Mobile TechTalk - Interesting talks from NSConference 6
JavaScript Web Development
Tweaking the interactive grid
iOS Memory Management Basics
Frontend application architecture, patterns, and workflows
Backbone intro
jQuery basics for Beginners
Objective C Memory Management
はじめてのUnitTest XCTestに触れて
iOS Beginners Lesson 4
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Swift Ready for Production?
Realm database
Introduction to meta-programming in scala
Ad

Similar to ES6 Primer (20)

PPTX
ES6 Overview
PDF
An Intro To ES6
PDF
ES6 General Introduction
PDF
ESCMAScript 6: Get Ready For The Future. Now
PDF
ES6 - Next Generation Javascript
PPTX
Getting started with ES6
PDF
JavaScript: Patterns, Part 1
PPTX
ES6 - JavaCro 2016
PPTX
ES6: Features + Rails
PDF
JavaScript in 2016
PPTX
JavaScript in 2016 (Codemotion Rome)
PDF
Javascript
PDF
ES6 - Level up your JavaScript Skills
PDF
ES6: The future is now
PDF
Fitc whats new in es6 for web devs
PDF
What's New in ES6 for Web Devs
PPTX
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
PPTX
Awesomeness of JavaScript…almost
PDF
JavaScript ES6
PDF
Angular Weekend
ES6 Overview
An Intro To ES6
ES6 General Introduction
ESCMAScript 6: Get Ready For The Future. Now
ES6 - Next Generation Javascript
Getting started with ES6
JavaScript: Patterns, Part 1
ES6 - JavaCro 2016
ES6: Features + Rails
JavaScript in 2016
JavaScript in 2016 (Codemotion Rome)
Javascript
ES6 - Level up your JavaScript Skills
ES6: The future is now
Fitc whats new in es6 for web devs
What's New in ES6 for Web Devs
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
Awesomeness of JavaScript…almost
JavaScript ES6
Angular Weekend
Ad

More from roblund (12)

PDF
Adventures in Real-World Data Science
PPTX
2 years into drinking the Microservice kool-aid (Fact and Fiction)
PDF
Jason Moore - Why releasing 50 features are less than 1 solution - BSDC 2016
PDF
Will Price - Venture Capital in Montana - BSDC 2016
PDF
Pete Sveen - How to Build, Grow, and Monetize Your Online Platform - BSDC 2016
PDF
Chris Omland - AWS Code Deploy - BSDC 2016
PPTX
Josef Verbanac - Voice is (a) Best Practice
PPTX
Emergence Of Code Schools
PPT
Nora McDougall-Collins - I Can Do That
PPTX
Better tests automagically (big sky dev con 2015)
PDF
Ben Werner - Mountains and startups
PDF
Jason Moore - Interaction design in enterprise teams
Adventures in Real-World Data Science
2 years into drinking the Microservice kool-aid (Fact and Fiction)
Jason Moore - Why releasing 50 features are less than 1 solution - BSDC 2016
Will Price - Venture Capital in Montana - BSDC 2016
Pete Sveen - How to Build, Grow, and Monetize Your Online Platform - BSDC 2016
Chris Omland - AWS Code Deploy - BSDC 2016
Josef Verbanac - Voice is (a) Best Practice
Emergence Of Code Schools
Nora McDougall-Collins - I Can Do That
Better tests automagically (big sky dev con 2015)
Ben Werner - Mountains and startups
Jason Moore - Interaction design in enterprise teams

Recently uploaded (20)

PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
web development for engineering and engineering
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Welding lecture in detail for understanding
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
composite construction of structures.pdf
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Arduino robotics embedded978-1-4302-3184-4.pdf
web development for engineering and engineering
Lecture Notes Electrical Wiring System Components
Internet of Things (IOT) - A guide to understanding
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Welding lecture in detail for understanding
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
bas. eng. economics group 4 presentation 1.pptx
Structs to JSON How Go Powers REST APIs.pdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Lesson 3_Tessellation.pptx finite Mathematics
composite construction of structures.pdf
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Foundation to blockchain - A guide to Blockchain Tech
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...

ES6 Primer

  • 2. Classes class Panel { constructor() { // make the thing } addItem(toAdd) { // add the item } }
  • 3. Arrow Functions arrayOfSomeStuff.filter(item => item < 20) toggle.addEventListener('click', (evt) => { // toggle the toggle })
  • 4. this class Layer { this.url = 'http://onxmaps.com/' .. pages.forEach(function(page) { console.log(this.url + page) }.bind(this)) } class Layer { this.url = 'http://onxmaps.com/' .. pages.forEach((page) => { console.log(this.url + page) }) }
  • 5. Objects var preferences = { fontSize: 16, // shorthand for theme: theme theme } * there are a couple other object literal changes that have varying levels of support and usefulness.
  • 6. Template Strings `using the backticks` `now supports multiline strings` `added ${adjective} support for interpolation`
  • 7. Destructuring var [name, type] = ['rob', 'shoe'] var {label, activity} = getActivity() var [title, , link] = ['señor', 'rob', 'http://...'] function findAccount({name: customerName}) { console.log(customerName) }
  • 8. Parameter Handling // defaults function getBook(title, version = 1) { .. } // rest or splat operator function addShoes(color, ...attributes) { // attributes is an array containing parameters 2+ attributes.forEach(..) } // spread operator function removeItem(name, type, element) { .. } removeItem(...['walrus', 'shoe', panelElement]) // spread can also be used in other areas, like // array or object literals (eg. simple concat) var allLayers = [layer1, layer2, ...everythingElse]
  • 9. const & let // block-scoped read only values const name = 'walrus' // block-scoped variable values let uri = '/account/' Do not become part of the window object like var
  • 10. for..of loops for (const item of pileOfItems) { console.log(item) } The problem with the old for..in loops: • Did weird things with objects (nested properties) • Did weird things with arrays (out of order) New for..of loops: • Flat out don't work with objects (stop iterating over object properties you animal) • Works great with arrays * caveat: for..of works with iterable collections like NodeList, but IE/Edge still has a rough time with this.
  • 11. Modules export function addItem(toAdd) { .. } export const scale = 12 export class Layer { .. } .. import { addItem, scale, Layer } from 'lib/layer' // import everything with * import * as layerLib from 'lib/layer' console.log(layerLib.scale) // default export export default class Layer { .. } .. import LayerHelper from 'lib/layer'
  • 12. Promises fetch(this.environment.apiUrl + '/v1/preferences', options) .then(checkStatus) .then(parseJson) .then((response) => { // do something with our parsed response object }) .catch((error) => { // handle your error }) Writing your asynchronous code in a synchronous fashion
  • 13. Other • Map, Set data structures • New helpful Math APIs • Unicode variables and matching • Generators