In this webinar, our COO Tasin Reza and the eCommerce director of eSpares.co.uk Farhan Hussain talks about their CRO program which does not only increased the efficiency but also achieved an amazing ROI of 30,000%.

Farhan talks about the process he adapted, tests he ran and also some of the winners that contributed to the overall success.

“You don’t need to always run complex tests”, says Farhan. “Sometimes really simple changes can make a massive difference to your bottom line conversion”.

Here is the Webinar replay, which was hosted by Convert.com. If you are interested to find out more about our A/B testing services or would like to see how you can achieve such ROI, simply drop us a line.

Webinar recording “30,000% ROI: How to hit this fabulous number with Your CRO Programme”

No comments yet

In this webinar, our COO Tasin Reza and the eCommerce director of eSpares.co.uk Farhan Hussain talks about their CRO program which does not only increased the efficiency but also achieved an amazing ROI of 30,000%.

Farhan talks about the process he adapted, tests he ran and also some of the winners that contributed to the overall success.

“You don’t need to always run complex tests”, says Farhan. “Sometimes really simple changes can make a massive difference to your bottom line conversion”.

Here is the Webinar replay, which was hosted by Convert.com. If you are interested to find out more about our A/B testing services or would like to see how you can achieve such ROI, simply drop us a line.

Wondering how to increase conversions, but confused where to start? What if your conversion is dropping due to your website, landing pages, or emails that influencing your conversion negatively? To make conversion better you can improve your conversion rate optimization (CRO) and know what exactly wrong, A/B testing can help you to determine.

A/B testing can be involved in testing two or more different versions of original pages like your web page, newsletters ads or landing pages and it will help you to find out which performs better. The result is an effective method that determines the best version driving more conversion. It means A/B testing plays a great role in your (CRO) conversion rate optimization plan. For the long run of your marketing operation, A/B testing process will be the significant factors that will increase your (CRO) conversion rate optimization efforts.

Here we are going to discuss how A/B testing can improve CRO with an impactful A/B testing process and plan. This technique will make your decision easy to invest more in CRO and understand visitor’s real problems and run strategic optimization programs in a better way. The techniques below would make your decision easy and finish the process faster, and get your conversion rate improved.

Develop your test without thinking too much!

The issue we’ve battled with in the past was over-investigating information before running the initial A/B test for a specific site. It was taking us two months by and large before we could demonstrate the consequences of our work. Here and thereafter this long time, we conveyed conversion rate drop – you can envision how baffled the customer was. The same applies to your manager, who puts cash in CRO.

Your objective ought to be to begin a test as quickly as time permits on the grounds that consistently you lose activity you could have tried. Also the open door cost of running less performing variant of your site.

By and large, you can spot serious issues with your site very quickly. Reports in Google Analytics should give you a few thoughts worth testing. Landing pages, Goal Flow, and Funnel Visualization reports are great spots to begin searching for low-hanging natural products.

Utilize guerrilla client testing to recognize usability issues with your site. Demonstrate your site to somebody who isn’t working with it on a consistent schedule (it could be your companion or even an irregular stranger in the closest coffeehouse) and request that he finish the most imperative client situation. Keep in mind, don’t over-investigate in the first place. Attempt these plans to think of a couple of fast issues and begin your test. It’s the best method to utilize your opportunity when you’re beginning a conversion optimization process.

1. Test Your Headlines

Headlines are the main objects a visitors will see on your website. So your landing page ought to have a smart and significant feature that promptly grabs their eye. It should be good enough to influence guests to need to peruse more, and inevitably change over.

2. Test your product page or buying description

Your headlines are to appeal more and influence the traffic to end the conversion to sales in the product description pages. The description page or the landing page should give adequate information to the visitors with minimum efforts and better usability features and how they can get benefitted or why will they buy, it should be engaging and also make them decide faster at the same time with appealing contents.

3. Test Your Design and Layout

Your web design may look stunning, however, it’s likely that it’s excessively diverting. It might keep guests from concentrating on the action you need them to take.

Your site features should be in a perfect with clean and minimal efforts, with an attention on the most essential components – like deals duplicate and CTA. It should be simple for clients to explore, which implies you may also need to create a responsive site to adjust to various devices of different sizes.

Apply the information from your client conduct tests to assemble a diverse plan and design varieties for A/B testing.

You can run a heat map to test where your visitors are performing most and you can redesign your test with better placement of a call to action button and does not matter if it’s a sign-up button or a buy now button.

Track results of you’re A/B Test

Tracking your A/B testing is the most important task to execute a successful conversion rate optimization process. In the beginning, it’s very common that you don’t get to know what to happen, but with each single of tracking, many ideas and lessons are generated and explored to make CRO better.

The reports of the A/B testing can make you quickly go back to where you started and check the current status and enable you to optimize even more with an impactful decision. Without a report, you may end up juggling things and features and may get into confusion with your goals and objectives you have set before the A/B testing process.

It’s a case of an A/B test take note of that we use to monitor conversion optimizations actions. The one above portrays a trial of expelling superfluous components from item page for activity originating from one of our e-commerce sites.

It’s also a priceless resource for have when you need to add someone else to the conversion optimizations teams. You basically allow the new partner access to the spreadsheet or wherever you’re keeping your record, and they can in a flash get up to speed on the authentic testing and results.

An ideal A/B testing records should include: 

  • Domain names, number of test, dates, and code
  • Test goals
  • Results
  • Screenshots of the controls and variables
  • Test hypothesis
  • Summary and achievement of each A/B testing made

We also recommend creating spreadsheets where you can list what you have learned from the test. It’s amazing assets to utilize and experiences can help for the future test, also it will help in making an effective team of expertise.

How A/B testing can improve your CRO?

No comments yet

Wondering how to increase conversions, but confused where to start? What if your conversion is dropping due to your website, landing pages, or emails that influencing your conversion negatively? To make conversion better you can improve your conversion rate optimization (CRO) and know what exactly wrong, A/B testing can help you to determine.

A/B testing can be involved in testing two or more different versions of original pages like your web page, newsletters ads or landing pages and it will help you to find out which performs better. The result is an effective method that determines the best version driving more conversion. It means A/B testing plays a great role in your (CRO) conversion rate optimization plan. For the long run of your marketing operation, A/B testing process will be the significant factors that will increase your (CRO) conversion rate optimization efforts.

Here we are going to discuss how A/B testing can improve CRO with an impactful A/B testing process and plan. This technique will make your decision easy to invest more in CRO and understand visitor’s real problems and run strategic optimization programs in a better way. The techniques below would make your decision easy and finish the process faster, and get your conversion rate improved.

Develop your test without thinking too much!

The issue we’ve battled with in the past was over-investigating information before running the initial A/B test for a specific site. It was taking us two months by and large before we could demonstrate the consequences of our work. Here and thereafter this long time, we conveyed conversion rate drop – you can envision how baffled the customer was. The same applies to your manager, who puts cash in CRO.

Your objective ought to be to begin a test as quickly as time permits on the grounds that consistently you lose activity you could have tried. Also the open door cost of running less performing variant of your site.

By and large, you can spot serious issues with your site very quickly. Reports in Google Analytics should give you a few thoughts worth testing. Landing pages, Goal Flow, and Funnel Visualization reports are great spots to begin searching for low-hanging natural products.

Utilize guerrilla client testing to recognize usability issues with your site. Demonstrate your site to somebody who isn’t working with it on a consistent schedule (it could be your companion or even an irregular stranger in the closest coffeehouse) and request that he finish the most imperative client situation. Keep in mind, don’t over-investigate in the first place. Attempt these plans to think of a couple of fast issues and begin your test. It’s the best method to utilize your opportunity when you’re beginning a conversion optimization process.

1. Test Your Headlines

Headlines are the main objects a visitors will see on your website. So your landing page ought to have a smart and significant feature that promptly grabs their eye. It should be good enough to influence guests to need to peruse more, and inevitably change over.

2. Test your product page or buying description

Your headlines are to appeal more and influence the traffic to end the conversion to sales in the product description pages. The description page or the landing page should give adequate information to the visitors with minimum efforts and better usability features and how they can get benefitted or why will they buy, it should be engaging and also make them decide faster at the same time with appealing contents.

3. Test Your Design and Layout

Your web design may look stunning, however, it’s likely that it’s excessively diverting. It might keep guests from concentrating on the action you need them to take.

Your site features should be in a perfect with clean and minimal efforts, with an attention on the most essential components – like deals duplicate and CTA. It should be simple for clients to explore, which implies you may also need to create a responsive site to adjust to various devices of different sizes.

Apply the information from your client conduct tests to assemble a diverse plan and design varieties for A/B testing.

You can run a heat map to test where your visitors are performing most and you can redesign your test with better placement of a call to action button and does not matter if it’s a sign-up button or a buy now button.

Track results of you’re A/B Test

Tracking your A/B testing is the most important task to execute a successful conversion rate optimization process. In the beginning, it’s very common that you don’t get to know what to happen, but with each single of tracking, many ideas and lessons are generated and explored to make CRO better.

The reports of the A/B testing can make you quickly go back to where you started and check the current status and enable you to optimize even more with an impactful decision. Without a report, you may end up juggling things and features and may get into confusion with your goals and objectives you have set before the A/B testing process.

It’s a case of an A/B test take note of that we use to monitor conversion optimizations actions. The one above portrays a trial of expelling superfluous components from item page for activity originating from one of our e-commerce sites.

It’s also a priceless resource for have when you need to add someone else to the conversion optimizations teams. You basically allow the new partner access to the spreadsheet or wherever you’re keeping your record, and they can in a flash get up to speed on the authentic testing and results.

An ideal A/B testing records should include: 

  • Domain names, number of test, dates, and code
  • Test goals
  • Results
  • Screenshots of the controls and variables
  • Test hypothesis
  • Summary and achievement of each A/B testing made

We also recommend creating spreadsheets where you can list what you have learned from the test. It’s amazing assets to utilize and experiences can help for the future test, also it will help in making an effective team of expertise.

A/B testing, a method that is widely known for its revolutionary use of enhancing customer experiences that would end up with the better conversion. It is one of the best online promotional and marketing strategy tools for any of the business. A/B testing can be used to test anything from website’s heading to email newsletters or even campaign’s running with search engine ads and display advertising. In e-commerce, it can also be used to test the action buttons, checkout experiences, and overall user experiences. The results are the real-time data which can be used to compare the experiences and pick the best results to make the decision easy.

A well planned A/B testing can play a vital role in increasing the efficiency of the marketing efforts. Choosing the most effective method for an increased conversion in a promotion and implementing them makes the marketing efforts more profitable and successful.

The data-driven decisions are used considering many of the variables across the range of communication methods. Following the year 2000, Google has successfully started to use A/B testing to determine growing number of search results and analyses the best way to show them in the listing pages and the rest Is history!

How is A/B Testing used?

A/B testing helps to determine the little differences in each of the customer interactions in a marketing campaign that influence their behavior. The changes can be as small as the changes in the letters of a title in a newsletter or an email, the text structure in a banner or something can be as big as the image itself, call to action buttons or layout of a landing page. It is actually the idea to test two variation with a controlled group of customers and find out the successful one. It can be repeated again and again to improve the contents and improve marketing communication with customers.

The common practice of A/B testing which is proven to be useful:

  • E-Newsletters
  • Email marketing campaigns
  • Websites
  • Apps
  • Internet advertising (banner/PPC/AdWords

How does A/B testing work?

The first A/B testing of any business should come with identifying the key metrics of the business and how that business define its success factors of their marketing campaigns. It can be the number of clicks, sales, sign-ups, average time spends, downloads, and etc. This then is used to set up two or more variables with a controlled number of audiences to go through the variables. It is always recommended not to pick more than one metrics at a time or it’s always challenging to know the one that made the differences. To analyze the results of the best output, it should be tested simultaneously in similar variations and select the most successful variation for final use.

For instance, while testing web pages, the existing version shall be kept as the control and make the second version for the test, and split the traffic with a ratio or even you can divide the traffic equally. This is some of the highly technical tasks, and to ease the process, some of the tools are being used where all the process of creating variations, splitting traffic and measuring the results can be done for free, for example, Google Analytics Content Experiments. There are also widely used tools which are premium and specializes in conversion rate optimization which will run the A/B testing and will make a recommendation that will aid the total marketing efforts, some of the best tools around are Optimizely, Monetate, A/B tasty, Adobe Target, etc.

What to test with A/B testing?

Webpage or Landing Pages

If you are a Magazine your key metrics would be the number of sign-ups you will receive for promotional campaigns. Taking the different version of a promotion where your sign up page call to action button will be optimized and increase sign-ups. For instance, you might get the idea with a new slogan which would make it better from the existing one. Here, the new slogans would be the test (variation A) and the existing would be the control (Variation B). ¬ You can then drive traffic to them equally to both the variations for a period of time. After the test end, we can see the results and which drives more sign up. The best result would then be picked following the campaign or be the same as the earlier versions depending on the results.

Examples of the variables that can be tested

  • Subject titles and subtitles
  • Product descriptions
  • Text (length, style)
  • Offers
  • Price
  • Images
  • Call to action button (text, color, position)
  • Colour schemes
  • Forms (length, question)
  • Page layouts
  • Shipping/Return Policies

While running an A/B test, it is always necessary to keep the sample size statistically relevant, for instance, if you get 2-3 sign-ups in one day, then the result won’t be relevant due to the size, the greater the sample size, the more reliable the result. Also, the result will depend on the performance differences, for example from a campaign if we expect an increase in sign up of 5% from a blue button, we need to analyze the number changes to make the results relevant. When we test the results in tens of thousands, 5.6% is a significant change, but if we take a number that will do a test with 15-20 results, then the result won’t make any sense. For testing in low traffic, scientific results are very hard to achieve, in this cases, the repeat test can be carried to get an insight into the test and get the best conversion rate.

Newsletters and Emails

Newsletters and email marketing are one of the greatest marketing tools that can keep you on the edge over your competitors. Each small visuals and contents can make a huge difference in defining your success, from experimenting with titles which make the receiver to open the email or not, and lots of other titles, call to action buttons, colors, etc. can make the difference in click-through rate. Developing a successful test development plan and executing them can make your campaign lot more success with scientific results.

Insights

A/B testing does not only helps us to pick up the best performing variation for better conversion rate but also the data we get can be used to other areas of marketing efforts and make the decision easier. If we know a blue call to action button working best across other tested areas, we can implement the same things in other places that can make the results more optimized. And when we know what type of newsletters has been successful, we can design another campaign saving decision-making times over promotional materials.

What is A/B testing in Digital Marketing?

No comments yet

A/B testing, a method that is widely known for its revolutionary use of enhancing customer experiences that would end up with the better conversion. It is one of the best online promotional and marketing strategy tools for any of the business. A/B testing can be used to test anything from website’s heading to email newsletters or even campaign’s running with search engine ads and display advertising. In e-commerce, it can also be used to test the action buttons, checkout experiences, and overall user experiences. The results are the real-time data which can be used to compare the experiences and pick the best results to make the decision easy.

A well planned A/B testing can play a vital role in increasing the efficiency of the marketing efforts. Choosing the most effective method for an increased conversion in a promotion and implementing them makes the marketing efforts more profitable and successful.

The data-driven decisions are used considering many of the variables across the range of communication methods. Following the year 2000, Google has successfully started to use A/B testing to determine growing number of search results and analyses the best way to show them in the listing pages and the rest Is history!

How is A/B Testing used?

A/B testing helps to determine the little differences in each of the customer interactions in a marketing campaign that influence their behavior. The changes can be as small as the changes in the letters of a title in a newsletter or an email, the text structure in a banner or something can be as big as the image itself, call to action buttons or layout of a landing page. It is actually the idea to test two variation with a controlled group of customers and find out the successful one. It can be repeated again and again to improve the contents and improve marketing communication with customers.

The common practice of A/B testing which is proven to be useful:

  • E-Newsletters
  • Email marketing campaigns
  • Websites
  • Apps
  • Internet advertising (banner/PPC/AdWords

How does A/B testing work?

The first A/B testing of any business should come with identifying the key metrics of the business and how that business define its success factors of their marketing campaigns. It can be the number of clicks, sales, sign-ups, average time spends, downloads, and etc. This then is used to set up two or more variables with a controlled number of audiences to go through the variables. It is always recommended not to pick more than one metrics at a time or it’s always challenging to know the one that made the differences. To analyze the results of the best output, it should be tested simultaneously in similar variations and select the most successful variation for final use.

For instance, while testing web pages, the existing version shall be kept as the control and make the second version for the test, and split the traffic with a ratio or even you can divide the traffic equally. This is some of the highly technical tasks, and to ease the process, some of the tools are being used where all the process of creating variations, splitting traffic and measuring the results can be done for free, for example, Google Analytics Content Experiments. There are also widely used tools which are premium and specializes in conversion rate optimization which will run the A/B testing and will make a recommendation that will aid the total marketing efforts, some of the best tools around are Optimizely, Monetate, A/B tasty, Adobe Target, etc.

What to test with A/B testing?

Webpage or Landing Pages

If you are a Magazine your key metrics would be the number of sign-ups you will receive for promotional campaigns. Taking the different version of a promotion where your sign up page call to action button will be optimized and increase sign-ups. For instance, you might get the idea with a new slogan which would make it better from the existing one. Here, the new slogans would be the test (variation A) and the existing would be the control (Variation B). ¬ You can then drive traffic to them equally to both the variations for a period of time. After the test end, we can see the results and which drives more sign up. The best result would then be picked following the campaign or be the same as the earlier versions depending on the results.

Examples of the variables that can be tested

  • Subject titles and subtitles
  • Product descriptions
  • Text (length, style)
  • Offers
  • Price
  • Images
  • Call to action button (text, color, position)
  • Colour schemes
  • Forms (length, question)
  • Page layouts
  • Shipping/Return Policies

While running an A/B test, it is always necessary to keep the sample size statistically relevant, for instance, if you get 2-3 sign-ups in one day, then the result won’t be relevant due to the size, the greater the sample size, the more reliable the result. Also, the result will depend on the performance differences, for example from a campaign if we expect an increase in sign up of 5% from a blue button, we need to analyze the number changes to make the results relevant. When we test the results in tens of thousands, 5.6% is a significant change, but if we take a number that will do a test with 15-20 results, then the result won’t make any sense. For testing in low traffic, scientific results are very hard to achieve, in this cases, the repeat test can be carried to get an insight into the test and get the best conversion rate.

Newsletters and Emails

Newsletters and email marketing are one of the greatest marketing tools that can keep you on the edge over your competitors. Each small visuals and contents can make a huge difference in defining your success, from experimenting with titles which make the receiver to open the email or not, and lots of other titles, call to action buttons, colors, etc. can make the difference in click-through rate. Developing a successful test development plan and executing them can make your campaign lot more success with scientific results.

Insights

A/B testing does not only helps us to pick up the best performing variation for better conversion rate but also the data we get can be used to other areas of marketing efforts and make the decision easier. If we know a blue call to action button working best across other tested areas, we can implement the same things in other places that can make the results more optimized. And when we know what type of newsletters has been successful, we can design another campaign saving decision-making times over promotional materials.

What are the benefits of arrow functions in JavaScript?

  • They are more concise.
  • They have implicit returns. (We’ll get into this below.)
  • They do not rebind the value of this when you use an arrow function inside another function. (We’ll get into this in a later post.)

How do I convert my ES5 functions to ES6 arrow functions?

Let’s start with a simple example using .map().

// Let's define an array of first names:
const names = ['joe', 'rache', 'micaela'];
// If I want to add my last name to each I'll run the following function using .map():
const fullNames = names.map(function(name) {
return `${name} cardillo`;
});
// In the console when I call:
names
// It returns:
['joe', 'rache', 'micaela']
// Then if I call the function:
fullNames
// It returns:
["joe cardillo", "rache cardillo", "micaela cardillo"]

To start, delete the word ‘function’ and replace it with a fat arrow =>

const fullNames = names.map((name) => {
return `${name} cardillo`;
});

If you have only one parameter you can remove the parenthesis from it:

const fullNames = names.map(name => {
return `${name} cardillo`;
});

You can also do an “implicit return.”

But first, what is an explicit return?

An explicit return is when you explicitly write the word return in the function.

To do an implicit return, remove the word return, then move what you are returning up to the same line as the rest of the function. You can remove the curly brackets.

// Explicit return:
const fullNames = names.map(name => {
return `${name} cardillo`;
});
// Implicit return:
const fullNames = names.map(name => `${name} cardillo`);

If there is no parameter you can replace it with parenthesis:

const fullNames = names.map(() => `hey cardillo!`);
// Returns:
["hey cardillo!", "hey cardillo!", "hey cardillo!"]

Arrow functions are always anonymous functions.

Before describing an anonymous function, let’s first answer the question, “What is a named function?”

// In ES5 a named function can be written as follows:
function myFavFood(food) {
console.log(`My favorite food is ${food}!`);
}
// myFavFood is the name of the function.
// Calling this in the console:
myFavFood('pizza');
// Returns:
My favorite food is pizza!

In the above arrow functions, notice that we set all of them equal to a constvariable called fullNames.

So why would we want to set our arrow function equal to a variable?

One reason is that it can help us debug JavaScript errors, since sometimes the line number isn’t enough to narrow down where it’s coming from.

Using the food example, we can assign the arrow function to a const variable called myFavFood.

const myFavFood = (food) => { console.log(`My favorite food is ${food}!`) }
// In the console:
myFavFood('pizza');
// Returns:
My favorite food is pizza!

An introductory guide to ES6 arrow functions in JavaScript

No comments yet

What are the benefits of arrow functions in JavaScript?

  • They are more concise.
  • They have implicit returns. (We’ll get into this below.)
  • They do not rebind the value of this when you use an arrow function inside another function. (We’ll get into this in a later post.)

How do I convert my ES5 functions to ES6 arrow functions?

Let’s start with a simple example using .map().

// Let's define an array of first names:
const names = ['joe', 'rache', 'micaela'];
// If I want to add my last name to each I'll run the following function using .map():
const fullNames = names.map(function(name) {
return `${name} cardillo`;
});
// In the console when I call:
names
// It returns:
['joe', 'rache', 'micaela']
// Then if I call the function:
fullNames
// It returns:
["joe cardillo", "rache cardillo", "micaela cardillo"]

To start, delete the word ‘function’ and replace it with a fat arrow =>

const fullNames = names.map((name) => {
return `${name} cardillo`;
});

If you have only one parameter you can remove the parenthesis from it:

const fullNames = names.map(name => {
return `${name} cardillo`;
});

You can also do an “implicit return.”

But first, what is an explicit return?

An explicit return is when you explicitly write the word return in the function.

To do an implicit return, remove the word return, then move what you are returning up to the same line as the rest of the function. You can remove the curly brackets.

// Explicit return:
const fullNames = names.map(name => {
return `${name} cardillo`;
});
// Implicit return:
const fullNames = names.map(name => `${name} cardillo`);

If there is no parameter you can replace it with parenthesis:

const fullNames = names.map(() => `hey cardillo!`);
// Returns:
["hey cardillo!", "hey cardillo!", "hey cardillo!"]

Arrow functions are always anonymous functions.

Before describing an anonymous function, let’s first answer the question, “What is a named function?”

// In ES5 a named function can be written as follows:
function myFavFood(food) {
console.log(`My favorite food is ${food}!`);
}
// myFavFood is the name of the function.
// Calling this in the console:
myFavFood('pizza');
// Returns:
My favorite food is pizza!

In the above arrow functions, notice that we set all of them equal to a constvariable called fullNames.

So why would we want to set our arrow function equal to a variable?

One reason is that it can help us debug JavaScript errors, since sometimes the line number isn’t enough to narrow down where it’s coming from.

Using the food example, we can assign the arrow function to a const variable called myFavFood.

const myFavFood = (food) => { console.log(`My favorite food is ${food}!`) }
// In the console:
myFavFood('pizza');
// Returns:
My favorite food is pizza!

Arrow functions were introduced with ES6 as a new syntax for writing JavaScript functions. They save developers time and simplify function scope. They are undoubtedly one of the more popular features of ES6.

Here is a function is written in ES5 syntax:

function timesTwo (params) {
  return params * 2
}
timesTwo(4);  // 8

Now, here is the same function expressed as an arrow function:

var timesTwo = params => params * 2

timesTwo(4); // 8

It’s much shorter! We are able to omit the curly braces and the return statement due to implicit returns (but only if there is no block — more on this below).

It is important to understand how the arrow function behaves differently compared to the regular ES5 functions.

One thing you will quickly notice is the variety of syntaxes available in arrow functions. Let’s run through some of the common ones:

1. No parameters

If there are no parameters, you can place an empty parentheses before =>.

() => 42

In fact, you don’t even need the parentheses!

_ => 42

2. Single parameter

With these functions, parentheses are optional:

x => 42  || (x) => 42

3. Multiple parameters

Parentheses are required for these functions:

(x, y) => 42

4. Statements (as opposed to expressions)

In its most basic form, a function expression produces a value, while a function statement performs an action.

With the arrow function, it is important to remember that statements need to have curly braces. Once the curly braces are present, you always need to writereturn as well.

Here is an example of the arrow function used with an if statement:

var feedTheCat = (cat) => {
  if (cat === 'hungry') {
    return 'Feed the cat';
  } else {
    return 'Do not feed the cat';
  }
}

5. “Block body”

If your function is in a block, you must also use the explicit return statement:

var addValues = (x, y) => {
  return x + y
}

6. Object Literals

If you are returning an object literal, it needs to be wrapped in parentheses. This forces the interpreter to evaluate what is inside the parentheses, and the object literal is returned.

x =>({ y: x })

Syntactically anonymous

It is important to note that arrow functions are anonymous, which means that they are not named.

This anonymity creates some issues:

  1. Harder to debug

When you get an error, you will not be able to trace the name of the function or the exact line number where it occurred.

2. No self-referencing

If your function needs to have a self-reference at any point (e.g. recursion, event handler that needs to unbind), it will not work.

In classic function expressions, the this keyword is bound to different values based on the context in which it is called. With arrow functions however, this is lexically bound. It means that it usesthis from the code that contains the arrow function.

For example, look at the setTimeout function below:

// ES5
var obj = {
  id: 42,
  counter: function counter() {
    setTimeout(function() {
      console.log(this.id);
    }.bind(this), 1000);
  }
};

In the ES5 example, .bind(this) is required to help pass the this context into the function. Otherwise, by default this would be undefined.

// ES6
var obj = {
  id: 42,
  counter: function counter() {
    setTimeout(() => {
      console.log(this.id);
    }, 1000);
  }
};

ES6 arrow functions can’t be bound to a this keyword, so it will lexically go up a scope, and use the value of this in the scope in which it was defined.

When you should not use Arrow Functions

After learning a little more about arrow functions, I hope you understand that they do not replace regular functions.

Here are some instances where you probably wouldn’t want to use them:

  1. Object methods

When you call cat.jumps, the number of lives does not decrease. It is because this is not bound to anything, and will inherit the value of this from its parent scope.

var cat = {
  lives: 9,
  jumps: () => {
    this.lives--;
  }
}

2. Callback functions with dynamic context

If you need your context to be dynamic, arrow functions are not the right choice. Take a look at this event handler below:

var button = document.getElementById('press');
button.addEventListener('click', () => {
  this.classList.toggle('on');
});

If we click the button, we would get a TypeError. It is because this is not bound to the button, but instead bound to its parent scope.

3. When it makes your code less readable

It is worth taking into consideration the variety of syntax we covered earlier. With regular functions, people know what to expect. With arrow functions, it may be hard to decipher what you are looking at straightaway.

When you should use them

Arrow functions shine best with anything that requires this to be bound to the context, and not the function itself.

Despite the fact that they are anonymous, I also like using them with methods such as map and reduce, because I think it makes my code more readable. To me, the pros outweigh the cons.

Proper ways of using ES6 arrow functions in JavaScript

No comments yet

Arrow functions were introduced with ES6 as a new syntax for writing JavaScript functions. They save developers time and simplify function scope. They are undoubtedly one of the more popular features of ES6.

Here is a function is written in ES5 syntax:

function timesTwo (params) {
  return params * 2
}
timesTwo(4);  // 8

Now, here is the same function expressed as an arrow function:

var timesTwo = params => params * 2

timesTwo(4); // 8

It’s much shorter! We are able to omit the curly braces and the return statement due to implicit returns (but only if there is no block — more on this below).

It is important to understand how the arrow function behaves differently compared to the regular ES5 functions.

One thing you will quickly notice is the variety of syntaxes available in arrow functions. Let’s run through some of the common ones:

1. No parameters

If there are no parameters, you can place an empty parentheses before =>.

() => 42

In fact, you don’t even need the parentheses!

_ => 42

2. Single parameter

With these functions, parentheses are optional:

x => 42  || (x) => 42

3. Multiple parameters

Parentheses are required for these functions:

(x, y) => 42

4. Statements (as opposed to expressions)

In its most basic form, a function expression produces a value, while a function statement performs an action.

With the arrow function, it is important to remember that statements need to have curly braces. Once the curly braces are present, you always need to writereturn as well.

Here is an example of the arrow function used with an if statement:

var feedTheCat = (cat) => {
  if (cat === 'hungry') {
    return 'Feed the cat';
  } else {
    return 'Do not feed the cat';
  }
}

5. “Block body”

If your function is in a block, you must also use the explicit return statement:

var addValues = (x, y) => {
  return x + y
}

6. Object Literals

If you are returning an object literal, it needs to be wrapped in parentheses. This forces the interpreter to evaluate what is inside the parentheses, and the object literal is returned.

x =>({ y: x })

Syntactically anonymous

It is important to note that arrow functions are anonymous, which means that they are not named.

This anonymity creates some issues:

  1. Harder to debug

When you get an error, you will not be able to trace the name of the function or the exact line number where it occurred.

2. No self-referencing

If your function needs to have a self-reference at any point (e.g. recursion, event handler that needs to unbind), it will not work.

In classic function expressions, the this keyword is bound to different values based on the context in which it is called. With arrow functions however, this is lexically bound. It means that it usesthis from the code that contains the arrow function.

For example, look at the setTimeout function below:

// ES5
var obj = {
  id: 42,
  counter: function counter() {
    setTimeout(function() {
      console.log(this.id);
    }.bind(this), 1000);
  }
};

In the ES5 example, .bind(this) is required to help pass the this context into the function. Otherwise, by default this would be undefined.

// ES6
var obj = {
  id: 42,
  counter: function counter() {
    setTimeout(() => {
      console.log(this.id);
    }, 1000);
  }
};

ES6 arrow functions can’t be bound to a this keyword, so it will lexically go up a scope, and use the value of this in the scope in which it was defined.

When you should not use Arrow Functions

After learning a little more about arrow functions, I hope you understand that they do not replace regular functions.

Here are some instances where you probably wouldn’t want to use them:

  1. Object methods

When you call cat.jumps, the number of lives does not decrease. It is because this is not bound to anything, and will inherit the value of this from its parent scope.

var cat = {
  lives: 9,
  jumps: () => {
    this.lives--;
  }
}

2. Callback functions with dynamic context

If you need your context to be dynamic, arrow functions are not the right choice. Take a look at this event handler below:

var button = document.getElementById('press');
button.addEventListener('click', () => {
  this.classList.toggle('on');
});

If we click the button, we would get a TypeError. It is because this is not bound to the button, but instead bound to its parent scope.

3. When it makes your code less readable

It is worth taking into consideration the variety of syntax we covered earlier. With regular functions, people know what to expect. With arrow functions, it may be hard to decipher what you are looking at straightaway.

When you should use them

Arrow functions shine best with anything that requires this to be bound to the context, and not the function itself.

Despite the fact that they are anonymous, I also like using them with methods such as map and reduce, because I think it makes my code more readable. To me, the pros outweigh the cons.