Menu

Syntax Comparison of ES5 vs ES6
📰

Syntax Comparison of ES5 vs ES6

DEV Community: react·Abdullah Al Nafiu·4 days ago
#8DTDuT3n
#devtoreact#devto#dev#name#users
Reading 0:00
15s threshold

Basically, I was revising JavaScript fundamentals. While doing that, I had a curious thought that led me to write content on it. And this is a common topic roaming all over the internet.

## Demo Data

const users = [

{ id: 1, name: "Rafi", age: 22, role: "intern" },

{ id: 2, name: "Nila", age: 17, role: "student" },

{ id: 3, name: "Sami", age: 28, role: "developer" },

{ id: 4, name: "Tina", age: 31, role: "developer" },

];

## ES6 functional expression using template literals

// Option A: Print each user using .forEach() users . forEach ( u => console . log ( ` ${ u . name } ( ${ u . age } )` ));

// Option B: Create a new array of strings using .map() const names = users . map ( u => ` ${ u . name } ( ${ u . age } )` ); console . log ( names );

Enter fullscreen mode

Exit fullscreen mode

## ES5 functional expression

// Option A: Print each user using .forEach() users . forEach ( function ( u ) { console . log ( u . name + " ( " + u .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.