Tutorials Modern JavaScript (ES6+) for Beginners

Arrow Functions Explained

Learn Arrow Functions Explained in our free Modern JavaScript (ES6+) for Beginners series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

On this page
Arrow Functions Explained
Lesson 3 of 12 · Part 1 — Modern Basics · Modern JavaScript (ES6+) for Beginners
Course: Modern JavaScript (ES6+) for Beginners · Lesson: 3/12 · Read time: ~16 min · Level: Beginner · ES version: ES2015 (ES6) and above

Arrow Functions Explained

Arrow functions (=>) are a shorter way to write functions. They appear in React event handlers, array methods, and Node.js middleware. Every modern codebase uses them daily.

Syntax comparison

// Old way
function add(a, b) {
  return a + b;
}

// Arrow function — same behavior
const add = (a, b) => a + b;

// Multiple lines — use { } and return
const greet = (name) => {
  const msg = 'Welcome, ' + name;
  return msg;
};

When to use arrow functions

  • Callbacks: items.map(item => item.price)
  • Short helpers: const double = n => n * 2
  • React: onClick={() => setOpen(true)}
🌍 Real-world example — Filter paid invoices
const invoices = [
  { id: 1, amount: 500, paid: true },
  { id: 2, amount: 1200, paid: false },
  { id: 3, amount: 799, paid: true }
];

const paidTotal = invoices
  .filter(inv => inv.paid)
  .map(inv => inv.amount)
  .reduce((sum, amt) => sum + amt, 0);

console.log(paidTotal); // 1299

Arrow vs regular function — this

Arrow functions do not have their own this. They inherit this from the surrounding scope. That is why React class components used bind(), but functional components + arrows “just work”.

const timer = {
  seconds: 0,
  start() {
    setInterval(() => {
      this.seconds++;  // ✅ this = timer object
    }, 1000);
  }
};
⚠️ Common Mistake: Using arrow functions as object methods when you need dynamic this — use regular function syntax for methods: start() { } not start: () => { } in some cases.
💡 Tip: If the body is one expression, you can omit return and braces: x => x * 2.
👨‍🏫 Teaching note: Have students rewrite three old function declarations as arrows — muscle memory before React.

Continue learning

Previous: let, const & Block Scope

Next: Template Literals & Modern Strings

Course home: All 12 lessons

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Junior Detailed
Explain JavaScript in the context of Modern JavaScript (ES6+) for Beginners.
Short answer: JavaScript runs single-threaded with an event loop. Closures capture lexical scope; promises/async handle I/O without blocking the UI thread. How to structure your answer (60–90 seconds) Define JavaScript i…
Mid Detailed
What are common mistakes teams make with Components when using Modern JavaScript (ES6+) for Beginners?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Components in plain language…
Senior Detailed
How would you debug a production issue related to State in a Modern JavaScript (ES6+) for Beginners application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define State in plain language for…
Mid Detailed
Compare two approaches to API integration—when would you choose each?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define API integration in plain lan…
Junior Detailed
Describe a real-world scenario where Performance mattered in a Modern JavaScript (ES6+) for Beginners project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Performance in plain languag…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Modern JavaScript (ES6+) for Beginners
Course syllabus
Part 1 — Modern Basics
Part 2 — Write Less Code
Part 3 — Data & Collections
Part 4 — Async & Modules
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details