SlideShare a Scribd company logo
INTRODUCTION TO ES2015
Presentation by /Kiran Abburi @kiran_abburi
ABOUT ME
Consultant & Corporate Trainer
Works primarily with reactjs projects
Offers reactjs training as well
ES2015
New features of javascript
Useful for writing concise code
Need to use babel for ES2015 to ES5 transpilation
CONST
Const is for Single Assignment
Usecases
Defining constants
Variables that doesn't change after first assignment
const MAX_HEIGHT = 500
MAX_HEIGHT = 600 // Throws error
const completedTodos = todos.filter(function (todo) {
return todo.completed
})
LET
let is block scoped
use let instead of var
let i = 5
for (let i = 0; i < 10; i++) {
}
console.log(i) // 5
var i = 5
for (var i = 0; i < 10; i++) {
}
console.log(i) // 10
ARROW FUNCTIONS
=> syntax for function shorthand
ES2015
const completedTodos = todos.filter(todo => todo.completed)
const completedTodos = todos.filter((todo) => {
return todo.completed
})
ES5
var completedTodos = todos.filter(function (todo) {
return todo.completed
})
ARROW FUNCTIONS
arrows share the same lexical this as their surrounding
code
ES2015
{
counter: 0,
incrementCounter() {
setInterval(() => this.counter = this.counter + 1, 1000)
}
}
ES5
{
counter: 0,
incrementCounter: function() {
var that = this
setInterval(funciton () {
that.counter = that.counter + 1
}, 1000)
}
}
CLASSES
Classes support prototype-based inheritance
The constructor method for creating and initializing an
object created with a class
Static methods are called without instantiating their class
Instance methods are run on class
class Fruit {
constructor(price) {
this.price = price;
}
static defaultValues() {
return {price : 1}
}
calculatePrice(units) {
return this.price * units
}
}
const f1 = new Fruit(2)
const f2 = new Fruit(5)
f1.calculatePrice(10) // 20
f2.calculatePrice(10) // 50
Fruit.defaultValues() // {price: 1}
CLASSES
class Fruit {
constructor(price) {
this.price = price;
}
calculatePrice(units) {
return this.price * units
}
}
class Apple extends Fruit {
constructor(price) {
super(price)
}
}
const a1 = new Apple(2)
a1.calculatePrice(10) // 20
TEMPLATE STRINGS
Multiline strings
ES2015
`line1 text
line2 text`
ES5
'line1 text' + 'n' + 'line2 text'
TEMPLATE STRINGS
Interpolate variables
ES2015
const msg = `Hello ${firstName} ${lastName}`
ES5
var msg = 'Hello ' + firstName + ' ' + lastName
DESTRUCTURING
Array destructuring
const [a, ,c] = [1,2,3];
a === 1;
c === 3;
Object destructuring
const values = {a: 1, b: 2, c: 3}
const {a, c} = values
a === 1;
c === 3;
DEFAULT FUNCTION PARAMETERS
const f(x = 2) {
return x
}
f() === 2
f(5) === 5
REST OPERATOR
const f(x, ...y) {
// x === 1
// y === [2, 3, 4]
}
f(1, 2, 3, 4)
SPREED OPERATOR
function f(x, y, z) {
// x === 1
// y === 2
// z === 3
}
f(...[1,2,3])
SET
let mySet = new Set([1, 2, 3, 4, 5])
mySet.add(6)
mySet.add(5)
mySet.has(5) // true
mySet.size // 6
mySet.delete(5)
for(let i of mySet.values()) {
console.log(i)
}
mySet.forEach(function (item) {
console.log(item)
})
MAP
let myMap = new Map()
myMap.set('x', 5)
myMap.get('x') // 5
myMap.size // 1
myMap.delete('x')
MAP ITERATIONS
let myMap = new Map([['x', 1], ['y', 2], ['z', 3]])
for (let key of myMap.keys()) {
console.log(key)
}
for (let key of myMap.values()) {
console.log(key)
}
for (let [key, value] of myMap.entries()) {
console.log(key, value)
}
PROMISES
let p1 = new Promise(function (resolve, reject) {
setTimeout(() => {
resolve('success')
}, 1000)
})
p1
.then((data) => console.log('on resolve', data))
.catch((error) => console.log('on reject', error))
GENERATORS
function* numbers() {
console.log('1')
yield 1
console.log('2')
yield 2
console.log('3')
yield 3
}
const num = numbers()
console.log(num.next()) // prints '1' and returns {"value":1,"done":false}
console.log(num.next()) // prints '2' and returns {"value":2,"done":false}
console.log(num.next()) // prints '3' and returns {"value":3,"done":false}
console.log(num.next()) // returns {"done":true}
GENERATORS
function* fibonacci() {
let pre = 0, cur = 1;
while (true) {
[pre, cur] = [cur, pre + cur];
yield cur
}
}
const fib = fibonacci()
console.log(fib.next()) // {value: 1, done: false}
console.log(fib.next().value) // 2
console.log(fib.next().value) // 3
console.log(fib.next().value) // 5
console.log(fib.next().value) // 8
GENERATORS
function* fibonacci() {
let pre = 0, cur = 1;
while (true) {
[pre, cur] = [cur, pre + cur];
yield cur
}
}
for (let n of fibonacci()) {
console.log(n)
if (n > 100) {
break
}
}
MODULES
Modules help us organize the code in seperate files
Avoid global namespace collision
Easy to share code across projects
Simplifies using opensource code in our project
MODULES
// math.js
function subtract (x, y) {
return x - y
}
export default function add (x, y) {
return x + y
}
// app.js
import add from './math'
MODULES
// math.js
export function subtract (x, y) {
return x - y
}
export function add (x, y) {
return x + y
}
// app.js
import {add, subtract} from './math'
or
// import * as math from './math'
// math.add, math.subtract
MODULES
// math.js
export function subtract (x, y) {
return x - y
}
export function add (x, y) {
return x + y
}
export default calc() {
}
// app.js
import calc, {add, subtract} from './math'
QUESTIONS

More Related Content

PPTX
C Programming Language Part 7
PPTX
C Programming Language Step by Step Part 2
PDF
Lecture 4
PPTX
EcmaScript unchained
PPT
c++ Lecture 2
PDF
C++ Programming - 2nd Study
PDF
Operator overloading
PDF
Stl algorithm-Basic types
C Programming Language Part 7
C Programming Language Step by Step Part 2
Lecture 4
EcmaScript unchained
c++ Lecture 2
C++ Programming - 2nd Study
Operator overloading
Stl algorithm-Basic types

What's hot (20)

PDF
Matlab code of chapter 4
PDF
C++ Question on References and Function Overloading
PPTX
C Programming Language Part 6
PDF
C++ Programming - 4th Study
PDF
C++ Programming - 11th Study
PPTX
F# intro
PDF
C++ Programming - 3rd Study
PDF
C++ TUTORIAL 2
PDF
C++ TUTORIAL 5
PPTX
Synapse india dotnet development overloading operater part 3
PDF
When RV Meets CEP (RV 2016 Tutorial)
PDF
Data Structure - 2nd Study
PDF
Implementing stack
PDF
JavaScript ES10 and React Js Introduction
DOC
Infix to-postfix examples
DOC
C tech questions
PPTX
Function basics
PDF
GeoGebra JavaScript CheatSheet
PPT
C++ control loops
PDF
C++ TUTORIAL 1
Matlab code of chapter 4
C++ Question on References and Function Overloading
C Programming Language Part 6
C++ Programming - 4th Study
C++ Programming - 11th Study
F# intro
C++ Programming - 3rd Study
C++ TUTORIAL 2
C++ TUTORIAL 5
Synapse india dotnet development overloading operater part 3
When RV Meets CEP (RV 2016 Tutorial)
Data Structure - 2nd Study
Implementing stack
JavaScript ES10 and React Js Introduction
Infix to-postfix examples
C tech questions
Function basics
GeoGebra JavaScript CheatSheet
C++ control loops
C++ TUTORIAL 1
Ad

Similar to Introduction to ES2015 (20)

PPTX
Academy PRO: ES2015
PDF
Workshop 10: ECMAScript 6
PDF
ECMAScript 6 and beyond
ODP
EcmaScript 6
PPTX
ES6: Features + Rails
ODP
ES6 PPT FOR 2016
PDF
Impress Your Friends with EcmaScript 2015
PPTX
Getting started with ES6
PDF
Javascript
PDF
JavaScript in 2016
PPTX
JavaScript in 2016 (Codemotion Rome)
PPTX
Es6 hackathon
PDF
ES6 General Introduction
PDF
Introduction to ECMAScript 2015
PPTX
ECMAScript 2015
PDF
ES6, WTF?
PPTX
Typescript barcelona
PDF
ES6 Simplified
PDF
ECMAScript2015
PPTX
ECMA5 and ES6 Promises
Academy PRO: ES2015
Workshop 10: ECMAScript 6
ECMAScript 6 and beyond
EcmaScript 6
ES6: Features + Rails
ES6 PPT FOR 2016
Impress Your Friends with EcmaScript 2015
Getting started with ES6
Javascript
JavaScript in 2016
JavaScript in 2016 (Codemotion Rome)
Es6 hackathon
ES6 General Introduction
Introduction to ECMAScript 2015
ECMAScript 2015
ES6, WTF?
Typescript barcelona
ES6 Simplified
ECMAScript2015
ECMA5 and ES6 Promises
Ad

Recently uploaded (20)

PPTX
ai tools demonstartion for schools and inter college
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Digital Strategies for Manufacturing Companies
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
AI in Product Development-omnex systems
PPTX
Transform Your Business with a Software ERP System
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
history of c programming in notes for students .pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
System and Network Administraation Chapter 3
PPT
Introduction Database Management System for Course Database
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
ai tools demonstartion for schools and inter college
Online Work Permit System for Fast Permit Processing
Digital Strategies for Manufacturing Companies
Odoo Companies in India – Driving Business Transformation.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Odoo POS Development Services by CandidRoot Solutions
Internet Downloader Manager (IDM) Crack 6.42 Build 41
AI in Product Development-omnex systems
Transform Your Business with a Software ERP System
Softaken Excel to vCard Converter Software.pdf
PTS Company Brochure 2025 (1).pdf.......
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
ManageIQ - Sprint 268 Review - Slide Deck
history of c programming in notes for students .pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
System and Network Administraation Chapter 3
Introduction Database Management System for Course Database
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Operating system designcfffgfgggggggvggggggggg

Introduction to ES2015

  • 1. INTRODUCTION TO ES2015 Presentation by /Kiran Abburi @kiran_abburi
  • 2. ABOUT ME Consultant & Corporate Trainer Works primarily with reactjs projects Offers reactjs training as well
  • 3. ES2015 New features of javascript Useful for writing concise code Need to use babel for ES2015 to ES5 transpilation
  • 4. CONST Const is for Single Assignment Usecases Defining constants Variables that doesn't change after first assignment const MAX_HEIGHT = 500 MAX_HEIGHT = 600 // Throws error const completedTodos = todos.filter(function (todo) { return todo.completed })
  • 5. LET let is block scoped use let instead of var let i = 5 for (let i = 0; i < 10; i++) { } console.log(i) // 5 var i = 5 for (var i = 0; i < 10; i++) { } console.log(i) // 10
  • 6. ARROW FUNCTIONS => syntax for function shorthand ES2015 const completedTodos = todos.filter(todo => todo.completed) const completedTodos = todos.filter((todo) => { return todo.completed }) ES5 var completedTodos = todos.filter(function (todo) { return todo.completed })
  • 7. ARROW FUNCTIONS arrows share the same lexical this as their surrounding code ES2015 { counter: 0, incrementCounter() { setInterval(() => this.counter = this.counter + 1, 1000) } } ES5 { counter: 0, incrementCounter: function() { var that = this setInterval(funciton () { that.counter = that.counter + 1 }, 1000) } }
  • 8. CLASSES Classes support prototype-based inheritance The constructor method for creating and initializing an object created with a class Static methods are called without instantiating their class Instance methods are run on class class Fruit { constructor(price) { this.price = price; } static defaultValues() { return {price : 1} } calculatePrice(units) { return this.price * units } } const f1 = new Fruit(2) const f2 = new Fruit(5) f1.calculatePrice(10) // 20 f2.calculatePrice(10) // 50 Fruit.defaultValues() // {price: 1}
  • 9. CLASSES class Fruit { constructor(price) { this.price = price; } calculatePrice(units) { return this.price * units } } class Apple extends Fruit { constructor(price) { super(price) } } const a1 = new Apple(2) a1.calculatePrice(10) // 20
  • 10. TEMPLATE STRINGS Multiline strings ES2015 `line1 text line2 text` ES5 'line1 text' + 'n' + 'line2 text'
  • 11. TEMPLATE STRINGS Interpolate variables ES2015 const msg = `Hello ${firstName} ${lastName}` ES5 var msg = 'Hello ' + firstName + ' ' + lastName
  • 12. DESTRUCTURING Array destructuring const [a, ,c] = [1,2,3]; a === 1; c === 3; Object destructuring const values = {a: 1, b: 2, c: 3} const {a, c} = values a === 1; c === 3;
  • 13. DEFAULT FUNCTION PARAMETERS const f(x = 2) { return x } f() === 2 f(5) === 5
  • 14. REST OPERATOR const f(x, ...y) { // x === 1 // y === [2, 3, 4] } f(1, 2, 3, 4)
  • 15. SPREED OPERATOR function f(x, y, z) { // x === 1 // y === 2 // z === 3 } f(...[1,2,3])
  • 16. SET let mySet = new Set([1, 2, 3, 4, 5]) mySet.add(6) mySet.add(5) mySet.has(5) // true mySet.size // 6 mySet.delete(5) for(let i of mySet.values()) { console.log(i) } mySet.forEach(function (item) { console.log(item) })
  • 17. MAP let myMap = new Map() myMap.set('x', 5) myMap.get('x') // 5 myMap.size // 1 myMap.delete('x')
  • 18. MAP ITERATIONS let myMap = new Map([['x', 1], ['y', 2], ['z', 3]]) for (let key of myMap.keys()) { console.log(key) } for (let key of myMap.values()) { console.log(key) } for (let [key, value] of myMap.entries()) { console.log(key, value) }
  • 19. PROMISES let p1 = new Promise(function (resolve, reject) { setTimeout(() => { resolve('success') }, 1000) }) p1 .then((data) => console.log('on resolve', data)) .catch((error) => console.log('on reject', error))
  • 20. GENERATORS function* numbers() { console.log('1') yield 1 console.log('2') yield 2 console.log('3') yield 3 } const num = numbers() console.log(num.next()) // prints '1' and returns {"value":1,"done":false} console.log(num.next()) // prints '2' and returns {"value":2,"done":false} console.log(num.next()) // prints '3' and returns {"value":3,"done":false} console.log(num.next()) // returns {"done":true}
  • 21. GENERATORS function* fibonacci() { let pre = 0, cur = 1; while (true) { [pre, cur] = [cur, pre + cur]; yield cur } } const fib = fibonacci() console.log(fib.next()) // {value: 1, done: false} console.log(fib.next().value) // 2 console.log(fib.next().value) // 3 console.log(fib.next().value) // 5 console.log(fib.next().value) // 8
  • 22. GENERATORS function* fibonacci() { let pre = 0, cur = 1; while (true) { [pre, cur] = [cur, pre + cur]; yield cur } } for (let n of fibonacci()) { console.log(n) if (n > 100) { break } }
  • 23. MODULES Modules help us organize the code in seperate files Avoid global namespace collision Easy to share code across projects Simplifies using opensource code in our project
  • 24. MODULES // math.js function subtract (x, y) { return x - y } export default function add (x, y) { return x + y } // app.js import add from './math'
  • 25. MODULES // math.js export function subtract (x, y) { return x - y } export function add (x, y) { return x + y } // app.js import {add, subtract} from './math' or // import * as math from './math' // math.add, math.subtract
  • 26. MODULES // math.js export function subtract (x, y) { return x - y } export function add (x, y) { return x + y } export default calc() { } // app.js import calc, {add, subtract} from './math'