Javascript ES6 Features for Salesforce developers

Arrow Functions:

Arrow functions were introduced in ES6. Arrow functions allow us to write shorter function syntax. Arrow function .this represents the owner of the function.

If the function has only one statement, and the statement returns a value, you can remove the brackets and the return keyword.
[var helloStr = function(){
  return "Hello";
// using arrow function
var helloStr = () => "Hello";]
If you have a single parameter and return value then no need braces, and if you have a more then one parameter then you need braces.
[// single parameter
var discount = amount => amount *0.10;
// Multiple parameters
var sum = ( a, b) => a+b;
// Multiple parameters with multiple lines of code, need return keywork
var tax = (basic, deductions, others) => {
var sum = basic*0.10;
return sum +deductions * others;

 Rest parameter(...): 

The rest parameter allows us to represent an indefinite number of arguments as an array. The rest parameter have to be the last argument, as its job is to collect all the remaining arguments into an array.
[var finalAmount = (discount, ...products) => {
    let sum = 0;
    for(let i of products){
    return sum * discount;

Spread Operator: 

It's similar to the Rest operator. It will take an array and pass to a list of parameters to a function.
[var x = [1,2,3];
var y = [...x]; // op: 1,2,3
var z = [...x,...[4,5]]; // op: 1,2,3,4,5
var j = [..."123"]; // op: "1","2","3"]

Object Literals:

Object literal is a comma-separated list of name-value pairs wrapped in object. Object literals encapsulate data, enclosing it in a tidy package.
[var price = 10;
var quantity = 5;
var bill = {price, quantity, "total amount" : () => this.price*this.quantity};
bill.price; // op: 10
bill["total amount"](); // OP: 50]
one more example.
[var name = 'Apple';
var price = 10;
var details = {[name]:price};
details; // op: {Apple: 10}
details.Apple; // op: 10 ]

For..Of loop:

Loops through the elements/values of an iterable object.
[var fruits = ['Apple', 'Banana','Kiwi'];
for(var item of fruits){
// Op:  Apple
// Banana
// Kiwi]
 one more example.
[var helloStr = 'Hello';
for(var item of helloStr){
// OP: H
//    e
//    l(2)
//    0]
yes, it can also iterate strings.

Template literals:

Template literals are introduced in ES6. Javascript Template literals are string literals that allow embedded expression inside it.
[var helloStr = 'Hello';
console.log(`This ${"is "+ helloStr} world!`);
// OP: this isHello world!]
one more example.
[var x = `A
// OP: A
//C ]
yes, whitespaces(Tab, New lines) are maintained.



Android Apps,1,Apex,7,Apex Methods,1,Batch Apex,2,Chrome Add-on,1,Chrome browser,1,Coding Best Practices,2,CRM Basics,1,cURL,1,Database Query,1,Dataset,1,Dynamic Apex,3,Dynamic SOQL,1,Einstein Analytics,9,Future Apex,1,Git,1,Google Chrome,1,IDs and Urls Hacks,1,JS for LWC,5,Lightning Components,2,lightning Page,1,Lightning Web Components,14,Linux for Windows users,1,LWC,16,LWC-JEST,7,Queueable Apex,1,Redirect page,1,REGEX,1,REST API,1,Salesforce CRM,1,Salesforce Errors,1,Salesforce Handy Commands,1,Salesforce Interview Questions,14,Salesforce Lightning,1,Salesforce New Features,1,Salesforce Tasks,2,Schedule Apex,1,SLDS,4,SVG Image,3,Test Class,1,Triggers,1,uiObjectInfoApi,1,Visualforce Pages,3,Visualforce Pagination,2,VS Code,2,Wave Analytics,7,Winter Release Notes,1,workbench,1,
SWDC WORLD (Software Development Center Of The World) - is a Multi author and Multi Technology Blog: Javascript ES6 Features for Salesforce developers
Javascript ES6 Features for Salesforce developers
Javascript ES6 Arrow functions for Salesforce developers,Arrow Functions Js, Rest parameter for apex developers,Spread Operator for salesforce developers, Object Literals in lwc,javascript for lightning web components
SWDC WORLD (Software Development Center Of The World) - is a Multi author and Multi Technology Blog
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy