javascript

Arrow Functions

Arrow functions, also called “fat arrows” were introduced with ES6 as a new syntax for writing Javascript functions.

By utilising a token (=>) that looks like a fat arrow, they are a more concise and elegant way of writing function expressions.

Basic Syntax

//ES5 Way
function myFunc() {
//statements here ...
}

//ES6 Way
myFunc = () => {
//statements here ...
}

Parentheses in ES6 functions are optional when only one parameter is passed.

myFunc = val => {
return val += 1;
}
alert(myFunc(2)); //3

But if no parameters are passed to the function, then parentheses are required.

Recent Posts

Common React Errors

React makes building user interfaces easier, but certain errors appear repeatedly, especially when working with…

11 hours ago

C Programming Cheat Sheet

The C programming language is a foundational, general-purpose computer programming language created by Dennis Ritchie at Bell Labs in 1972. Originally developed to…

19 hours ago

Homebrew Tutorial

What Is Homebrew? Homebrew is a package manager for macOS and Linux that makes it easy to…

4 days ago

10 Ways to Loop Through a JavaScript Array

JavaScript gives you several ways to iterate over an array. Some are better for simple…

6 days ago

Build a Node JS Web Server

A web server is the software responsible for receiving requests from clients, processing those requests,…

1 week ago

Shell Prompt Tutorial

A shell prompt is the text displayed by a command-line shell to show that it is ready…

2 weeks ago