js | ES6 Features |

Ranjith srt - Sep 9 - - Dev Community
Arrow Functions
Enter fullscreen mode Exit fullscreen mode

ES5

 function add(a, b) {

  return a + b;

}

Enter fullscreen mode Exit fullscreen mode

ES6


const add = (a, b) => a - b;

Variable Declarations

Enter fullscreen mode Exit fullscreen mode

ES5

var num1 = 10; //old feature 
Enter fullscreen mode Exit fullscreen mode

ES6


let num2 = 20;      // new features 

const PI = 3.145;

Enter fullscreen mode Exit fullscreen mode

Template Literals

ES5


var name = 'Alice';

console.log('Hello, + name + '!');

Enter fullscreen mode Exit fullscreen mode

ES6

console.log(Hello, ${name}!');
Enter fullscreen mode Exit fullscreen mode

Object Destructuring

ES5


var userOne = { firstName: 'John', lastName: 'Doe' };

console.log(userOne.firstName);

console.log(userOne.lastName);

Enter fullscreen mode Exit fullscreen mode

ES6

var userTwo = { firstName: 'Jane', lastName: 'Doe' }; 

const { firstName, lastName } = userTwo;

console.log(firstName);

console.log(lastName);

Enter fullscreen mode Exit fullscreen mode

Default Parameters

ES5


function greet (name) { 

  name = name || 'Guest';

console.log('Hello,+ name +'! ') ;

}

greet('Karthik');

Enter fullscreen mode Exit fullscreen mode

ES6


function greetUser(name = 'Guest') 

{ console.log('Hello, ${name}!`);

}

greetUser('Alex');

Enter fullscreen mode Exit fullscreen mode

String concatenate

ES5


let x = [1, 2, 3] ;

let y = [4, 5, 6] ; 

let z = x.concat(y); console.log(z);

Enter fullscreen mode Exit fullscreen mode

ES6


let combined = [...x, ...y]; 

console.log(combined);

Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .