DEV Community

Essential ES6 JavaScript Features Every JavaScript Developer Should Know

Gloria Tejuosho on May 01, 2024

As a developer, it's crucial to stay updated with recent technologies to remain relevant and streamline development processes. The newer the techno...
Collapse
 
miketalbot profile image
Mike Talbot ⭐

Pictures of code are not accessible to users that require assistive technology, it's much better to embed code directly in the post using the markup tags to syntax highlight it.

Collapse
 
gloriasilver profile image
Gloria Tejuosho

Alright, I'll take note.
Thanks for the feedback.

Collapse
 
efpage profile image
Eckehard • Edited

If you are unsure about the post editor, you will find a great explanation here. Code examples are introduced using three backticks followed by a language identifier, in this case JS or Javascript.

Collapse
 
tony_m_26104982fd5177227d profile image
Tony M

@gloriasilver I wouldn't bother. So few programmers use assistive technology that it's not worth the effort. They can always do the reverse image thing.

Collapse
 
jonrandy profile image
Info Comment hidden by post author - thread only accessible via permalink
Jon Randy 🎖️ • Edited

The array methods map, reduce, and filter were introduced in ES5.

Collapse
 
gloriasilver profile image
Gloria Tejuosho

Nope.
Array methods like map, reduce, and Filter were introduced in Es6.
Check for confirmation.

Collapse
 
jonrandy profile image
Thread Thread
 
gloriasilver profile image
Gloria Tejuosho

Alright.
I have checked.
Thank you for the clarification.🤙
I'll adjust the post.

Collapse
 
citronbrick profile image
CitronBrick

They even work in Internet Explorer 9.

Collapse
 
skitzdev profile image
Justin Praßl

"Notice the two methods perform the same function, but the arrow function provides a simpler way of declaring the function"
Important to mention is, that Arrow Functions doesnt have their own context. So when you do something like:

function fn() {
  console.log('parent', this)

  function x() {
    console.log(this)
  }

  const y = () => {
    console.log(this)
  }

  console.log(x(), y())
}
Enter fullscreen mode Exit fullscreen mode

the console log of y will point at the this of the parent but x would have its own context

Collapse
 
zalithka profile image
Andre Greeff

The 'Spread' operator iterates over an iterable element, such as a string, array, or object, and then spreads each value into individual items. This allows us to quickly copy them.

please be super careful with this one... spreading an array only creates a shallow copy, so presenting this as a way to "quickly copy them" is misleading and downright dangerous, especially to people who are still learning JS.

usually, I recommend that people only use the spread operator for changing data structures on-the-fly while passing arguments to a function, never for trying to make copies of existing data structures. in my mind, this is nothing but a fast track to impure functions that could create runtime issues that are ridiculously difficult to locate later on.. unit tests don't always help catch this either, especially since most unit tests will not have an environment that persists between runs.

the MDN docs do a very good job of explaining this behaviour, definitely worth taking the time to read. I'll include their sample code snippet here for easier reference:

const a = [[1], [2], [3]];
const b = [...a];

b.shift().shift();
// 1

// Oh no! Now array 'a' is affected as well:
console.log(a);
// [[], [2], [3]]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
suzukistumpy profile image
Info Comment hidden by post author - thread only accessible via permalink
Mark Edwards • Edited

You're missing some pretty fundamental differences with arrow functions over traditional functions that, I feel, your article would have benefitted enormously from including. Namely (and this from the first paragraph of the MDN article on arrow functions):

  • Arrow functions don't have their own bindings to this, arguments, or super, and should not be used as methods.
  • Arrow functions cannot be used as constructors. Calling them with new throws a TypeError. They also don't have access to the new.target keyword.
  • Arrow functions cannot use yield within their body and cannot be created as generator functions.

To my mind, the first bullet there is the most important to bear in mind since misunderstanding this binding is often a cause of unpredictable code.

Collapse
 
noman318 profile image
Shaikh Mohd Noman

The difference between the normal traditional function and the arrow could have been provided by a more precise example like the case of "this" in the normal function and arrow function.
BTW the blog is very helpful.

Collapse
 
xavierdev23 profile image
Xavierdev23

super on fire, this aricle

Collapse
 
citronbrick profile image
CitronBrick

ES6 (ES2015) came out in 2015. Currently we are using ES14 (ES 2023).
Nevertheless, an useful article as I've heard of colleges that hadn't updated their curriculum.

Some comments have been hidden by the post's author - find out more