SlideShare a Scribd company logo
What's new in ES2019
Chayanika Khatua
"Any application that can be
written in JavaScript, will
eventually by written in
JavaScript."
- Jeff Atwood, Co-founder of StackOverflow
2 / 48
We are 10.7 million developers
worldwide.
Together we support over 4.1 billion
users of the web.
3 / 48
Me, back in the day
Arrays
for (var i = 0; i < students.length; i++) {
newStudents.push(transform(students[i]));
}
Strings
...we write JavaScript very differently now.
var message = name + ', You have $' + dollars + ' in your account.
4 / 48
Me, now
5 / 48
What we're talking about
ECMAScript, a brief, not at all complete, history
So, what is new in ES2019?
How do proposals turn into features?
ESNext proposals
6 / 48
The year was 1995
7 / 48
Mocha is born
Brendan Eich creates
Mocha in 10 days
Java is really new and
trendy. JavaScript is
marketed as the
lightweight cousin.
Eventually renamed to
JavaScript in December
1995
8 / 48
JScript
Microsoft releases JScript in August 1996.
9 / 48
ECMA
Netscape approaches the European Computer Manufacturers
Association.
JavaScript and JScript are implementations.
The spec is called ECMAScript.
ECMAScript 1 released in 1997.
10 / 48
ES2019 Features
Array.prototype.flat
Flattens an array according to the depth specified.
const arr = [[1, 2], [3, 4, 5]];
const flattened = arr.flat(); // default depth is 1
// flattened = [1, 2, 3, 4, 5]
Specifying the depth:
const arr = [[1, 2], [[3]]];
const flattened = arr.flat(2);
// flattened = [1, 2, 3]
Arbitrary depth? Use Infinity.
12 / 48
Use case
const animals = await Promise.all([
getWildAnimals(),
getWingedCreatures(),
getPets(),
]);
// animals = [[ 🦊 , 🦁 ], [ 🐥 , 🦢 ], [ 🐱 ]];
const flattenedAnimals = animals.flat();
// flattenedAnimals = [ 🦊 , 🦁 , 🐥 , 🦢 , 🐱 ]
13 / 48
Array.prototype.flatMap
With map() every element is translated to exactly one output
element.
With flatMap() every element can be transformed into a variable
number of elements.
14 / 48
Working with data
// Folder = { files: [] }
const folders = [folder1, folder2, ...];
const toFiles = folder => folder.files;
// Alternative
const result = folders.map(toFiles).flat(1);
const result = folders.flatMap(toFiles);
// result = [file1, file2, file3, ...];
// Before flatMap, not performant
const result = folders.reduce(
(acc, folder) => acc.concat(folder.files)
, []);
15 / 48
Mapping and filtering
const numbers = [ 1, 2, 3, 4 ];
const doubleEven = num => {
if (num % 2 === 0) {
return [ num * 2 ];
}
return [];
};
const filteredAndDoubled = numbers.flatMap(doubleEven);
// filteredAndDoubled = [ 4, 8 ];
16 / 48
Array.prototype.smoosh?
17 / 48
Object.fromEntries
Counterpart to the Object.entries.
const obj = Object.fromEntries([
['a', 1],
['b', 2]
]);
// obj = {a: 1, b: 2}
console.log(Object.entries(obj));
// [ ['a', 1], ['b', 2] ]
18 / 48
Object transformation
const objectOG = { a: 1, b: 2, c: 3 };
const resultObject = Object.fromEntries(
Object.entries(objectOG)
.map(([ key, val ]) => [ key, val * 2 ])
);
// resultObject = { a: 2, b: 4, c: 6 }
Alternative, pre 2019
const result = Object.keys(objectOG).reduce((acc, key) => {
acc[key] = objectOG[key] * 2;
return acc;
}, {});
19 / 48
Maps and Objects
const map = new Map([
['a', 1],
['b', 2]
]);
const obj = Object.fromEntries(map);
// obj = {a: 1, b: 2}
20 / 48
Optional catch binding
Pre 2019
try {
// Try something dangerous
} catch (error) {
logger.error(error);
}
Post 2019
The error parameter can be dropped.
try {
data = JSON.parse(response);
} catch {
data = defaultData;
}
21 / 48
Array.prototype.sort stable
const arr = [
{ name: 'C', value: 90 },
{ name: 'A', value: 80 },
{ name: 'B', value: 80 },
];
// compareValueFunction compares the value property and should res
arr.sort(compareValueFunction);
// pre, possibly
[
{ name: 'B', value: 80 },
{ name: 'A', value: 80 },
{ name: 'C', value: 90 },
];
// post, required
[
{ name: 'A', value: 80 },
{ name: 'B', value: 80 },
{ name: 'C', value: 90 },
];
22 / 48
Recap ES2019
Array.prototype.{flat, flatMap}
Object.fromEntries
Optional catch binding
Array.prototype.sort stable
All these are supported in all modern browsers and Node 12+
23 / 48
The Evolution of ECMAScript
The TC39 proposal process
Technical committee 39 of ECMA International
ECMA 262 specification
Members are implementers that send delegates
Committee meets six times a year
A new process was defined after ES4 was abandoned, and ES6
was a massive release that took 6 years.
25 / 48
Stage 0 (Strawperson)
Format to allow input into the specification
Planned or presented to TC39
26 / 48
Stage 1 (Proposal)
Identified champion or champions who will advance the
addition.
Describe the problem or requirement
High level API
Potential concerns have been identified
27 / 48
Stage 2 (Draft)
Initial spec text
Incremental changes expected
The committee expects the feature to be developed and
eventually included in the standard
28 / 48
Stage 3 (Candidate)
At this stage, the proposal is considered complete
No further work is possible without implementation experience
Only changes considered critical based on implementation
experience
29 / 48
Classes right now
Classes were added in ES6
class Counter {
constructor() {
this.min = 0;
this.max = 100;
this._count = 0;
}
get count() {
return this._count;
}
increment() {
this._count++;
}
decrement() {
this._count--;
}
}
Counter.someStaticProp = 'Static';
30 / 48
As a User
const counter = new Counter();
console.log(counter.count); // 0
counter._count = 42;
console.log(counter.count); // 42
31 / 48
Class Fields (Stage 3)
class Counter {
static someStaticProp = 'Static';
this.min = 0;
this.max = 100;
this._count = 0;
get count() {
return this._count;
}
increment() {
this._count++;
}
decrement() {
this._count--;
}
}
Supported in Chrome 72, Node 12
32 / 48
Privacy matters (Stage 3)
class Counter {
#count = 0;
get count() {
return this.#count;
}
increment() {
this.#count++;
}
decrement() {
this.#count--;
}
}
33 / 48
As a User
const counter = new Counter();
console.log(counter.#count);
// SyntaxError
counter.#count = 42;
// SyntaxError
counter.count = 42;
// Tries to assign to the public field
Private class fields supported in Chrome 74, Node 12
34 / 48
Property access in JavaScript
// TypeError prone
const streetName = user.address.streetName;
// Pleasure to read
let streetName = user &&
user.address &&
user.address.streetName;
// Even better, ternaries
const streetName = user ? (
user.address ?
user.address.streetName : undefined
) : undefined;
35 / 48
Say ?. (Stage 3)
Enter optional chaining.
Optional chaining operator: ?.
Short circuits if encounters a nullish value.
Available as a Babel plugin, TypeScript 3.7
const streetName = user?.address?.streetName;
const street = user?.getAddress()?.streetName;
36 / 48
Assigning default values
const donut = incomingDonut ? incomingDonut : defaultDonut;
// alternative
const donut = incomingDonut || defaultDonut;
// except if this is a number, catch the zero's
// Or a boolean?!
const num = incomingNum == null ? defaultNum : incomingNum;
37 / 48
Nullish Coalescing Operator
const num = incomingNum ?? defaultNum;
Checks if a value is nullish.
In Kotlin, this is called the Elvis operator.
Available as a Babel plugin, TypeScript 3.7
38 / 48
Bringing it all together 💯
Soon, we could be writing code like this!
const streetName = user?.address?.streetName ?? 'No Street.';
39 / 48
Stage 4 (Finished)
Spec editor has signed off.
Ready to be included in the spec.
Test262 acceptance tests have been merged.
Two spec compliant implementations exist.
40 / 48
Numbers in JavaScript
Number can only represent values up to 253 - 1
const max = Number.MAX_SAFE_INTEGER;
// 9_007_199_254_740_991
max + 1;
// 9_007_199_254_740_992 ✅
max + 2;
// 9_007_199_254_740_992 ❌
(max + 1) === (max + 2);
// true 🤯
41 / 48
BigInt 🎉
A new primitive
Arbitrary precision integers
Works as expected with arithmetic operators
Does not work with Math functions
Chrome, Firefox, Node 12+
BigInt(Number.MAX_SAFE_INTEGER);
// 9_007_199_254_740_991n
BigInt(Number.MAX_SAFE_INTEGER) + 2n;
// 9_007_199_254_740_993n ✅
typeof 100;
// 'number'
typeof 100n;
// 'bigint'
100n + 100;
// TypeError
42 / 48
Promise.allSettled
Promise.all added in 2015
Promise.all short-circuits when one of the promises fails
Promise.allSettled returns a promise that resolves when each of
the promises has either been fulfilled or rejected.
const promise1 = Promise.resolve(3);
const promise2 = new Promise((resolve, reject) =>
setTimeout(reject, 100, 'foo'));
const promises = [promise1, promise2];
const results = await Promise.allSettled(promises);
results.forEach(result => console.log(result.status));
// expected output:
// "fulfilled"
// "rejected"
43 / 48
globalThis
So many JavaScript environments and all the related global
objects.
// A naive attempt at getting the global `this`. Don’t use this!
const getGlobalThis = () => {
if (typeof globalThis !== 'undefined') return globalThis;
if (typeof self !== 'undefined') return self;
if (typeof window !== 'undefined') return window;
if (typeof global !== 'undefined') return global;
// Note: this might still return the wrong result!
if (typeof this !== 'undefined') return this;
throw new Error('Unable to locate global `this`');
};
const theGlobalThis = getGlobalThis();
Now we just have globalThis, yay portability!
Unified mechanism to access the global this in any
environment.
44 / 48
Recap ESNext
ECMAScript is evolved by the TC39 committee
A new version is released every year
Proposals can change till they reach Stage 4
Stage 3 proposals-
Class enhancements
Optional chaining
Nullish Coalescing
Stage 4 proposals-
BigInt
Promise.allSettled
globalThis
45 / 48
Conclusion
JavaScript has come a long way since its inception in 1995.
We are a passionate, diverse and vocal community.
As a member of this community, you can participate in its
evolution!
Always bet on JavaScript! 🚀
46 / 48
Sources
https://github.com/tc39/proposals
https://v8.dev/
https://github.com/tc39/ecma262
https://github.com/tc39/test262
https://test262.report/
https://2ality.com/2017/04/flatmap.html
https://tech-insider.org/java/research/1995/1204.html
47 / 48
Thank you!
Questions?
chayanika.khatua@ing.com

More Related Content

What's hot

Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective cMayank Jalotra
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
aleks-f
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
HUST
 
Computer Science Programming Assignment Help
Computer Science Programming Assignment HelpComputer Science Programming Assignment Help
Computer Science Programming Assignment Help
Programming Homework Help
 
Computational Assignment Help
Computational Assignment HelpComputational Assignment Help
Computational Assignment Help
Programming Homework Help
 
Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012
aleks-f
 
Control System Homework Help
Control System Homework HelpControl System Homework Help
Control System Homework Help
Matlab Assignment Experts
 
Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Deepak Singh
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and Reagent
Maty Fedak
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
Stefan Marr
 
Task and Data Parallelism: Real-World Examples
Task and Data Parallelism: Real-World ExamplesTask and Data Parallelism: Real-World Examples
Task and Data Parallelism: Real-World Examples
Sasha Goldshtein
 
Kotlin Crash Course
Kotlin Crash CourseKotlin Crash Course
Kotlin Crash Course
Haim Michael
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
Knowledge Center Computer
 
Intake 38 5
Intake 38 5Intake 38 5
Intake 38 5
Mahmoud Ouf
 
Operating System Engineering
Operating System EngineeringOperating System Engineering
Operating System Engineering
Programming Homework Help
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Stefan Marr
 
Part - 2 Cpp programming Solved MCQ
Part - 2  Cpp programming Solved MCQ Part - 2  Cpp programming Solved MCQ
Part - 2 Cpp programming Solved MCQ
Knowledge Center Computer
 
Assignment Examples Final 07 Oct
Assignment Examples Final 07 OctAssignment Examples Final 07 Oct
Assignment Examples Final 07 OctSriram Raj
 
Object Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
Harjinder Singh
 
Lecture no 3
Lecture no 3Lecture no 3
Lecture no 3
hasi071
 

What's hot (20)

Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
 
Computer Science Programming Assignment Help
Computer Science Programming Assignment HelpComputer Science Programming Assignment Help
Computer Science Programming Assignment Help
 
Computational Assignment Help
Computational Assignment HelpComputational Assignment Help
Computational Assignment Help
 
Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012Dynamic C++ Silicon Valley Code Camp 2012
Dynamic C++ Silicon Valley Code Camp 2012
 
Control System Homework Help
Control System Homework HelpControl System Homework Help
Control System Homework Help
 
Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and Reagent
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
 
Task and Data Parallelism: Real-World Examples
Task and Data Parallelism: Real-World ExamplesTask and Data Parallelism: Real-World Examples
Task and Data Parallelism: Real-World Examples
 
Kotlin Crash Course
Kotlin Crash CourseKotlin Crash Course
Kotlin Crash Course
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
 
Intake 38 5
Intake 38 5Intake 38 5
Intake 38 5
 
Operating System Engineering
Operating System EngineeringOperating System Engineering
Operating System Engineering
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
 
Part - 2 Cpp programming Solved MCQ
Part - 2  Cpp programming Solved MCQ Part - 2  Cpp programming Solved MCQ
Part - 2 Cpp programming Solved MCQ
 
Assignment Examples Final 07 Oct
Assignment Examples Final 07 OctAssignment Examples Final 07 Oct
Assignment Examples Final 07 Oct
 
Object Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
 
Lecture no 3
Lecture no 3Lecture no 3
Lecture no 3
 

Similar to Whats new in ES2019

Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018
Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018
Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018
Codemotion
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing Scenario
Tara Hardin
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
Nitay Neeman
 
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Igalia
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
JAXLondon_Conference
 
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)
Hermann Hueck
 
Es6 overview
Es6 overviewEs6 overview
Es6 overview
Bertrand Chevrier
 
Implementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresImplementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphores
Gowtham Reddy
 
Why rust?
Why rust?Why rust?
Why rust?
Mats Kindahl
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
NVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読み
NVIDIA Japan
 
Chapter 2
Chapter 2Chapter 2
Methods
MethodsMethods
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docxFinal Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
voversbyobersby
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
Francesco Casalegno
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningCarol McDonald
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidity
Emanuel Mota
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
AOE
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
Caridy Patino
 

Similar to Whats new in ES2019 (20)

Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018
Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018
Pablo Magaz | ECMAScript 2018 y más allá | Codemotion Madrid 2018
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing Scenario
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Es6 overview
Es6 overviewEs6 overview
Es6 overview
 
Implementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphoresImplementing of classical synchronization problem by using semaphores
Implementing of classical synchronization problem by using semaphores
 
Why rust?
Why rust?Why rust?
Why rust?
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
NVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読み
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Methods
MethodsMethods
Methods
 
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docxFinal Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
Final Project SkeletonCipherClient.javaFinal Project SkeletonC.docx
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidity
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 

Recently uploaded

Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
AkolbilaEmmanuel1
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
manasideore6
 

Recently uploaded (20)

Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Steel & Timber Design according to British Standard
Steel & Timber Design according to British StandardSteel & Timber Design according to British Standard
Steel & Timber Design according to British Standard
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
 

Whats new in ES2019

  • 1. What's new in ES2019 Chayanika Khatua
  • 2. "Any application that can be written in JavaScript, will eventually by written in JavaScript." - Jeff Atwood, Co-founder of StackOverflow 2 / 48
  • 3. We are 10.7 million developers worldwide. Together we support over 4.1 billion users of the web. 3 / 48
  • 4. Me, back in the day Arrays for (var i = 0; i < students.length; i++) { newStudents.push(transform(students[i])); } Strings ...we write JavaScript very differently now. var message = name + ', You have $' + dollars + ' in your account. 4 / 48
  • 6. What we're talking about ECMAScript, a brief, not at all complete, history So, what is new in ES2019? How do proposals turn into features? ESNext proposals 6 / 48
  • 7. The year was 1995 7 / 48
  • 8. Mocha is born Brendan Eich creates Mocha in 10 days Java is really new and trendy. JavaScript is marketed as the lightweight cousin. Eventually renamed to JavaScript in December 1995 8 / 48
  • 9. JScript Microsoft releases JScript in August 1996. 9 / 48
  • 10. ECMA Netscape approaches the European Computer Manufacturers Association. JavaScript and JScript are implementations. The spec is called ECMAScript. ECMAScript 1 released in 1997. 10 / 48
  • 12. Array.prototype.flat Flattens an array according to the depth specified. const arr = [[1, 2], [3, 4, 5]]; const flattened = arr.flat(); // default depth is 1 // flattened = [1, 2, 3, 4, 5] Specifying the depth: const arr = [[1, 2], [[3]]]; const flattened = arr.flat(2); // flattened = [1, 2, 3] Arbitrary depth? Use Infinity. 12 / 48
  • 13. Use case const animals = await Promise.all([ getWildAnimals(), getWingedCreatures(), getPets(), ]); // animals = [[ 🦊 , 🦁 ], [ 🐥 , 🦢 ], [ 🐱 ]]; const flattenedAnimals = animals.flat(); // flattenedAnimals = [ 🦊 , 🦁 , 🐥 , 🦢 , 🐱 ] 13 / 48
  • 14. Array.prototype.flatMap With map() every element is translated to exactly one output element. With flatMap() every element can be transformed into a variable number of elements. 14 / 48
  • 15. Working with data // Folder = { files: [] } const folders = [folder1, folder2, ...]; const toFiles = folder => folder.files; // Alternative const result = folders.map(toFiles).flat(1); const result = folders.flatMap(toFiles); // result = [file1, file2, file3, ...]; // Before flatMap, not performant const result = folders.reduce( (acc, folder) => acc.concat(folder.files) , []); 15 / 48
  • 16. Mapping and filtering const numbers = [ 1, 2, 3, 4 ]; const doubleEven = num => { if (num % 2 === 0) { return [ num * 2 ]; } return []; }; const filteredAndDoubled = numbers.flatMap(doubleEven); // filteredAndDoubled = [ 4, 8 ]; 16 / 48
  • 18. Object.fromEntries Counterpart to the Object.entries. const obj = Object.fromEntries([ ['a', 1], ['b', 2] ]); // obj = {a: 1, b: 2} console.log(Object.entries(obj)); // [ ['a', 1], ['b', 2] ] 18 / 48
  • 19. Object transformation const objectOG = { a: 1, b: 2, c: 3 }; const resultObject = Object.fromEntries( Object.entries(objectOG) .map(([ key, val ]) => [ key, val * 2 ]) ); // resultObject = { a: 2, b: 4, c: 6 } Alternative, pre 2019 const result = Object.keys(objectOG).reduce((acc, key) => { acc[key] = objectOG[key] * 2; return acc; }, {}); 19 / 48
  • 20. Maps and Objects const map = new Map([ ['a', 1], ['b', 2] ]); const obj = Object.fromEntries(map); // obj = {a: 1, b: 2} 20 / 48
  • 21. Optional catch binding Pre 2019 try { // Try something dangerous } catch (error) { logger.error(error); } Post 2019 The error parameter can be dropped. try { data = JSON.parse(response); } catch { data = defaultData; } 21 / 48
  • 22. Array.prototype.sort stable const arr = [ { name: 'C', value: 90 }, { name: 'A', value: 80 }, { name: 'B', value: 80 }, ]; // compareValueFunction compares the value property and should res arr.sort(compareValueFunction); // pre, possibly [ { name: 'B', value: 80 }, { name: 'A', value: 80 }, { name: 'C', value: 90 }, ]; // post, required [ { name: 'A', value: 80 }, { name: 'B', value: 80 }, { name: 'C', value: 90 }, ]; 22 / 48
  • 23. Recap ES2019 Array.prototype.{flat, flatMap} Object.fromEntries Optional catch binding Array.prototype.sort stable All these are supported in all modern browsers and Node 12+ 23 / 48
  • 24. The Evolution of ECMAScript
  • 25. The TC39 proposal process Technical committee 39 of ECMA International ECMA 262 specification Members are implementers that send delegates Committee meets six times a year A new process was defined after ES4 was abandoned, and ES6 was a massive release that took 6 years. 25 / 48
  • 26. Stage 0 (Strawperson) Format to allow input into the specification Planned or presented to TC39 26 / 48
  • 27. Stage 1 (Proposal) Identified champion or champions who will advance the addition. Describe the problem or requirement High level API Potential concerns have been identified 27 / 48
  • 28. Stage 2 (Draft) Initial spec text Incremental changes expected The committee expects the feature to be developed and eventually included in the standard 28 / 48
  • 29. Stage 3 (Candidate) At this stage, the proposal is considered complete No further work is possible without implementation experience Only changes considered critical based on implementation experience 29 / 48
  • 30. Classes right now Classes were added in ES6 class Counter { constructor() { this.min = 0; this.max = 100; this._count = 0; } get count() { return this._count; } increment() { this._count++; } decrement() { this._count--; } } Counter.someStaticProp = 'Static'; 30 / 48
  • 31. As a User const counter = new Counter(); console.log(counter.count); // 0 counter._count = 42; console.log(counter.count); // 42 31 / 48
  • 32. Class Fields (Stage 3) class Counter { static someStaticProp = 'Static'; this.min = 0; this.max = 100; this._count = 0; get count() { return this._count; } increment() { this._count++; } decrement() { this._count--; } } Supported in Chrome 72, Node 12 32 / 48
  • 33. Privacy matters (Stage 3) class Counter { #count = 0; get count() { return this.#count; } increment() { this.#count++; } decrement() { this.#count--; } } 33 / 48
  • 34. As a User const counter = new Counter(); console.log(counter.#count); // SyntaxError counter.#count = 42; // SyntaxError counter.count = 42; // Tries to assign to the public field Private class fields supported in Chrome 74, Node 12 34 / 48
  • 35. Property access in JavaScript // TypeError prone const streetName = user.address.streetName; // Pleasure to read let streetName = user && user.address && user.address.streetName; // Even better, ternaries const streetName = user ? ( user.address ? user.address.streetName : undefined ) : undefined; 35 / 48
  • 36. Say ?. (Stage 3) Enter optional chaining. Optional chaining operator: ?. Short circuits if encounters a nullish value. Available as a Babel plugin, TypeScript 3.7 const streetName = user?.address?.streetName; const street = user?.getAddress()?.streetName; 36 / 48
  • 37. Assigning default values const donut = incomingDonut ? incomingDonut : defaultDonut; // alternative const donut = incomingDonut || defaultDonut; // except if this is a number, catch the zero's // Or a boolean?! const num = incomingNum == null ? defaultNum : incomingNum; 37 / 48
  • 38. Nullish Coalescing Operator const num = incomingNum ?? defaultNum; Checks if a value is nullish. In Kotlin, this is called the Elvis operator. Available as a Babel plugin, TypeScript 3.7 38 / 48
  • 39. Bringing it all together 💯 Soon, we could be writing code like this! const streetName = user?.address?.streetName ?? 'No Street.'; 39 / 48
  • 40. Stage 4 (Finished) Spec editor has signed off. Ready to be included in the spec. Test262 acceptance tests have been merged. Two spec compliant implementations exist. 40 / 48
  • 41. Numbers in JavaScript Number can only represent values up to 253 - 1 const max = Number.MAX_SAFE_INTEGER; // 9_007_199_254_740_991 max + 1; // 9_007_199_254_740_992 ✅ max + 2; // 9_007_199_254_740_992 ❌ (max + 1) === (max + 2); // true 🤯 41 / 48
  • 42. BigInt 🎉 A new primitive Arbitrary precision integers Works as expected with arithmetic operators Does not work with Math functions Chrome, Firefox, Node 12+ BigInt(Number.MAX_SAFE_INTEGER); // 9_007_199_254_740_991n BigInt(Number.MAX_SAFE_INTEGER) + 2n; // 9_007_199_254_740_993n ✅ typeof 100; // 'number' typeof 100n; // 'bigint' 100n + 100; // TypeError 42 / 48
  • 43. Promise.allSettled Promise.all added in 2015 Promise.all short-circuits when one of the promises fails Promise.allSettled returns a promise that resolves when each of the promises has either been fulfilled or rejected. const promise1 = Promise.resolve(3); const promise2 = new Promise((resolve, reject) => setTimeout(reject, 100, 'foo')); const promises = [promise1, promise2]; const results = await Promise.allSettled(promises); results.forEach(result => console.log(result.status)); // expected output: // "fulfilled" // "rejected" 43 / 48
  • 44. globalThis So many JavaScript environments and all the related global objects. // A naive attempt at getting the global `this`. Don’t use this! const getGlobalThis = () => { if (typeof globalThis !== 'undefined') return globalThis; if (typeof self !== 'undefined') return self; if (typeof window !== 'undefined') return window; if (typeof global !== 'undefined') return global; // Note: this might still return the wrong result! if (typeof this !== 'undefined') return this; throw new Error('Unable to locate global `this`'); }; const theGlobalThis = getGlobalThis(); Now we just have globalThis, yay portability! Unified mechanism to access the global this in any environment. 44 / 48
  • 45. Recap ESNext ECMAScript is evolved by the TC39 committee A new version is released every year Proposals can change till they reach Stage 4 Stage 3 proposals- Class enhancements Optional chaining Nullish Coalescing Stage 4 proposals- BigInt Promise.allSettled globalThis 45 / 48
  • 46. Conclusion JavaScript has come a long way since its inception in 1995. We are a passionate, diverse and vocal community. As a member of this community, you can participate in its evolution! Always bet on JavaScript! 🚀 46 / 48