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 .…