arrow functions basic usages in javascript

// An empty arrow function returns undefined
let empty = () => {};

(() => 'foobar')();
// Returns "foobar"
// (this is an Immediately Invoked Function Expression)

var simple = a => a > 15 ? 15 : a;
simple(16); // 15
simple(10); // 10

let max = (a, b) => a > b ? a : b;

// Easy array filtering, mapping, ...

var arr = [5, 6, 13, 0, 1, 18, 23];

var sum = arr.reduce((a, b) => a + b);
// 66

var even = arr.filter(v => v % 2 == 0);
// [6, 0, 18]

var double = arr.map(v => v * 2);
// [10, 12, 26, 0, 2, 36, 46]

// More concise promise chains
promise.then(a => {
  // ...
}).then(b => {
  // ...
});

// Parameterless arrow functions that are visually easier to parse
setTimeout( () => {
  console.log('I happen sooner');
  setTimeout( () => {
    // deeper code
    console.log('I happen later');
  }, 1);
}, 1);

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
arrow function javascript compatibility is it safe to use es6 arrow functions when do you use arrow functions what is the use of arrow function in javascript javascript class method with arrow functions what are arrow functions why do we need arrow functions javascript arrow functions arrow functions passing objects javascript arrow function support browser when to not use arrow function in jasvscript using arrow functions in for of any good reasons not to use arrow functions in js when to use arrow functions is arrow function an es6 feature what does this refer to in arrow function javascript js arrow function unlimited arguments javascript es5 arrow function handling this in arrow functions and functions expressions javascript const arrowfunction should i use arrow functions using this method in an arrow functions advantages of using arrow function in javascript when should you use arrow functions does es6 support arrow function does arrow functions have this keyword why can't you use arrow function with this in javascript for declaring methods arrow function and this in javascript js arrow function in parameter why do arrow functions not have this keyword and arguments in javascript what does arrow function do in javascript es6 named arrow functions how to do arrow functions why arrow functions are used how to write arrow functions es6 arrow function with parameters javascript arrow function without parameters how to use this with arrow functions arrow function uses use this in with arrow functions javascript when not to use arrow functions why to use arrow functions javascript arrow function with no parameters when should i use arrow functions what version of javascript were arrow functions released in js function arrow arrow function scope javascript arrow function in javascript benefits javascript use function variable insiede arrow function why use arrow functions arrow function javascript as a parameter arrow functions and this arrow function come from es6 or not what is the usefuless of arrow functions in javascript why do we use arrow functions arrow function with assignment js javascript what is an arrow function javascript what is n arrow function different arrow function in javascript arrow function javascript parameters arrow function javascript syntax arrow function inside method assign a function arrow function javascript arrow functions in javascript what is the use of arrow function js when are arrow functions better in javascript first js version with arrow functions arrow function syntax js how to write arrow function in javascript es6 arrow function example javascript arrow funcgtion advantages of arrow function in javascript when to use arrow function javascript js arrow functions this in arrow functions arrow functions in es6 js arrow function parameter arrow functions javascript somar arrow function javascript tutorial javascript arrow function this Arrow Functions method this in arrow function what is arrow function in javascript arrow functions javascript arrow function as method this bind arrow function javascript arrow functions this keyword arrow function example benefits of using arrow functions what is an arrow function in javascript javascript arrow functions arrow function basic usages in javacsript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source