SlideShare a Scribd company logo
1 of 17
ES6
Agenda
 Iterators, Generators, and Promises
 Promises
 Generators
 Iterators
 Maps and Sets
 Map and WeakMap
 Set and WeakSet
PROMISES
Promises in ES6
 Represents the state of an asynchronous operation, and has three different states
 Pending: The initial state of promise
 Fulfilled: The state of promise representing a successful operation
 Rejected: The state of promise representing a failed operation
 Create a promise like
 Where myPromiseObject is defined as
 Implement the “Fulfill” and “Reject” promise as
Promises in ES6
 Resolving multiple promises
 Resolve using a static method in “Promise” – Promise.all
 Promise.all returns a promise (All promise parameters should be in the fulfilled state for Promise.all to be fulfilled)
Generators
Generators in ES6
 Watching a movie on Netflix
 Your phone rings
 You pause the movie, to attend the phone
 You finish the call to resume the movie on Netflix, you don’t restart the movie
Generators in ES6
 A generator function is recognized by “function * function_name”
Iterators
Iterators in ES6
 Currently we can iterate through arrays like [‘Hi’, ‘This’, ‘is’, ‘an’, ‘array’]; using the for, while, or, for…of loops
 But how will we iterate through object using the same logic?
 Use iterators instead, using the “Symbol.iterator” keyword
 “Symbol.iterator” returns an “iterator” object.
 An ”iterator” object
 Has a method called “next” (What we saw in the generators)
 Return an object with keys “value” and “done” (eg: {value: 1, done: false})
Iterators in ES6
 Understanding Iterator through [Symbol.iterator]()
Set, Map, WeakSet,
WeakMap
Set in ES6
 Set is a collection of unique values
 Values can be primitive types, or object references (as long as they are unique);
 Create a set by “new Set()”
 Note that since I am trying to add the value “Sharma” twice, the set will ignore the last addition, and will have it only
once without throwing any errors
 Iterate over the set using the for…of loop or the forEach loop
Maps in ES6
 Maps are a store for key / value pairs. Key and value could be a primitives or object references
 Create a map using the ”new Map()”
 Keys of values in a map can be any thing (String, Integer, or an Object reference)
 Get all keys of a map by using the ”keys()” method
 Iterate over the map items using the forEach or the for…of loops
WeakMap in ES6
 WeakMap – a variant of a map that allows objects as keys and removes them once they become inaccessible by
other means.
 WeakMap doesn’t support methods keys(), values(), entries(), also, we cannot iterate over them.
 WeakMap only has the following functions
 weakMap.get(key)
 weakMap.set(key)
 weakMap.delete(key, value)
 weakMap.has(key);
 WeakMap v/s Map
Q & A
Thank You

More Related Content

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Recently uploaded (20)

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Es6 day2

  • 1. ES6
  • 2. Agenda  Iterators, Generators, and Promises  Promises  Generators  Iterators  Maps and Sets  Map and WeakMap  Set and WeakSet
  • 4. Promises in ES6  Represents the state of an asynchronous operation, and has three different states  Pending: The initial state of promise  Fulfilled: The state of promise representing a successful operation  Rejected: The state of promise representing a failed operation  Create a promise like  Where myPromiseObject is defined as  Implement the “Fulfill” and “Reject” promise as
  • 5. Promises in ES6  Resolving multiple promises  Resolve using a static method in “Promise” – Promise.all  Promise.all returns a promise (All promise parameters should be in the fulfilled state for Promise.all to be fulfilled)
  • 7. Generators in ES6  Watching a movie on Netflix  Your phone rings  You pause the movie, to attend the phone  You finish the call to resume the movie on Netflix, you don’t restart the movie
  • 8. Generators in ES6  A generator function is recognized by “function * function_name”
  • 10. Iterators in ES6  Currently we can iterate through arrays like [‘Hi’, ‘This’, ‘is’, ‘an’, ‘array’]; using the for, while, or, for…of loops  But how will we iterate through object using the same logic?  Use iterators instead, using the “Symbol.iterator” keyword  “Symbol.iterator” returns an “iterator” object.  An ”iterator” object  Has a method called “next” (What we saw in the generators)  Return an object with keys “value” and “done” (eg: {value: 1, done: false})
  • 11. Iterators in ES6  Understanding Iterator through [Symbol.iterator]()
  • 13. Set in ES6  Set is a collection of unique values  Values can be primitive types, or object references (as long as they are unique);  Create a set by “new Set()”  Note that since I am trying to add the value “Sharma” twice, the set will ignore the last addition, and will have it only once without throwing any errors  Iterate over the set using the for…of loop or the forEach loop
  • 14. Maps in ES6  Maps are a store for key / value pairs. Key and value could be a primitives or object references  Create a map using the ”new Map()”  Keys of values in a map can be any thing (String, Integer, or an Object reference)  Get all keys of a map by using the ”keys()” method  Iterate over the map items using the forEach or the for…of loops
  • 15. WeakMap in ES6  WeakMap – a variant of a map that allows objects as keys and removes them once they become inaccessible by other means.  WeakMap doesn’t support methods keys(), values(), entries(), also, we cannot iterate over them.  WeakMap only has the following functions  weakMap.get(key)  weakMap.set(key)  weakMap.delete(key, value)  weakMap.has(key);  WeakMap v/s Map
  • 16. Q & A