DEV Community

Cover image for What is your favourite ES6 feature?

What is your favourite ES6 feature?

Tanwa Sripan on June 29, 2022

Helloooo everyone! πŸ‘‹ It has been a while since I last posted, I have been rather busy the past 2 weeks! As the title suggests, I am curious to kno...
Collapse
 
pengeszikra profile image
Peter Vivo • Edited

generator function you can get in and leave (yield) so many times, it is perfect for declarative coding time consuming process. Modern usecase is redux-saga

really old poker example on codepen.io

   // example of use generators
   * singleRound(){

    for( let deal of this.dealing() ) yield deal

    for( let flop of this.theBetRound( 'Flop' ) ) yield flop

    for( let flop of this.theFlop() ) yield

    for( let turn of this.theBetRound( 'Turn' ) ) yield turn
    yield this.theTurn(); 

    for( let river of this.theBetRound( 'River' ) ) yield river
    yield this.theRiver(); 

    for( let showdown of this.theBetRound( 'Showdown' ) ) yield showdown

    let winnerIs = []
    for( let score of this.showScores( winnerIs )) yield score
    let winner = this.theShowdown( winnerIs )
    yield winner    
    winner.chips += this.dealer.drawBet()
    for( let pause of Array(10)) yield winner

    // yield this.theShowdown()
  }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
justtanwa profile image
Tanwa Sripan

Really cool, thank you for sharing!

Collapse
 
timkovik profile image
timkovik

Optional chaining is amazing

Collapse
 
justtanwa profile image
Tanwa Sripan

That's cool also, though I have not used it much

Collapse
 
cmgustin profile image
Chris Gustin

I’m a big fan of .forEach() and the related .filter() and .map() methods.

Much cleaner and easier to read than the old C-style iterative loops in my opinion, and a great addition to the language given how much of modern JS and front-end dev involves looping through large amounts of data in some way or another.

Collapse
 
justtanwa profile image
Tanwa Sripan

I agree, I also like array methods, they are very handy :D

Collapse
 
justtanwa profile image
Tanwa Sripan

That's really cool, I have not used Proxies before, do you have an example use case you have used in the past?

Collapse
 
darkwiiplayer profile image
π’ŽWii πŸ³οΈβ€βš§οΈ • Edited

Here is an example of how I use Proxies in the wild. They're one of my favourite things in JS; the sky is the limit for what you can build using them :D


EDIT: In case that code requires an explanation, here is the documentation.

Thread Thread
 
justtanwa profile image
Tanwa Sripan

Wow! A lot going on here, but it looks awesome :D Not sure I understand it all, but thank you for the example.

Collapse
 
admirnisic profile image
admirnisic

Do not know what is my favorite one but one cool feature which is on top of my list is default value for function parameters.

function sayHello(name = 'World') {
    return `Hello ${name}!`;
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mistval profile image
Randall

There are a lot of great features that came in ES6, but I would agree that Promises are my favorite, especially since they paved the way for async/await. Const, let, and classes are also great.

Collapse
 
andrewbaisden profile image
Andrew Baisden

Probably the new array methods.

Collapse
 
mrdulin profile image
official_dulin

Optional chain

Collapse
 
jcubic profile image
Jakub T. Jankiewicz • Edited

Mine are Proxy objects and default symbols that can be used for meta programming.

 
justtanwa profile image
Tanwa Sripan

Thank you for this example!

Collapse
 
blackeyv profile image
raymond-yan • Edited

Cool trick. Never thought about using destructuring like this.