React Prerequisites: JavaScript Essentials
โš›๏ธ React 18+ ๐ŸŸข Chapter 2 of 39 ๐Ÿ“‚ Phase 01: React Introduction ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: HTML/CSS Basics ยท Variables & Functions ยท Arrow Functions ยท Arrays & Objects ยท map()/filter() ยท Destructuring ยท Spread ยท Modules ยท Promises ยท async/await
React relies heavily on modern JavaScript features โ€” arrow functions, array methods like map() and filter(), destructuring, and async/await all appear constantly in real React code. This chapter is a focused refresher on exactly the JavaScript you need before JSX, props, and state will make sense.
1Arrow Functions and Destructuring

React code is written almost entirely using arrow functions and destructuring โ€” both appear in nearly every component you'll write from Chapter 4 onward.

๐Ÿ’ป Example 1: Arrow Functions & Destructuring
// Regular function
function add(a, b) {
  return a + b;
}

// Arrow function - same thing, shorter
const add = (a, b) => a + b;

// Destructuring an object
const student = { name: "Ravi", age: 20 };
const { name, age } = student;
console.log(name); // "Ravi"
2Arrays: map(), filter(), and the Spread Operator

map() and filter() are the two array methods you'll use constantly to turn data into UI (covered fully in Chapter 10 - Lists and Keys):

const numbers = [1, 2, 3, 4, 5];

const doubled = numbers.map(n => n * 2);       // [2, 4, 6, 8, 10]
const evens = numbers.filter(n => n % 2 === 0); // [2, 4]

// Spread operator - copies an array or object instead of mutating it
const original = [1, 2, 3];
const copy = [...original, 4];   // [1, 2, 3, 4] - original is untouched

The spread operator (...) is especially important in React because state should never be mutated directly โ€” you'll see this exact pattern again in Chapter 13.

3Promises and async/await

Fetching data from an API (Chapter 21) always involves asynchronous code:

async function getUser() {
  const response = await fetch("/api/user");
  const data = await response.json();
  return data;
}

await pauses the function until the Promise resolves, letting you write asynchronous code that reads top-to-bottom like normal, synchronous code โ€” much cleaner than chaining .then() calls.

โš ๏ธ Skipping This Chapter and Jumping Straight into JSX

It's tempting to skip straight to "building things," but destructuring, map(), and arrow functions appear on almost every line of real React code. Struggling with both React and unfamiliar JavaScript syntax at the same time is the single biggest reason beginners get stuck early โ€” even a quick refresher here saves real time later.

๐Ÿ’ป Hands-on Interactive Practice Challenge

Given an array of student objects, use map() to create a new array of just their names, and filter() to keep only students scoring above 80.

React Practice Challenge โ–ถ Run in Compiler
const students = [
  { name: "Amit", score: 92 },
  { name: "Neha", score: 75 },
  { name: "Raj", score: 88 }
];

const names = students.map(s => s.name);
const toppers = students.filter(s => s.score > 80);

console.log(names);
console.log(toppers);
Run This Challenge in Online JS IDE โ†’
โ“ Frequently Asked Questions (FAQ)

Q Do I need to master all of JavaScript before starting React?

No โ€” just the specific patterns covered in this chapter: arrow functions, destructuring, map/filter, spread, and async/await. You'll deepen your JavaScript knowledge naturally as you build more React projects.

Q What's the difference between map() and forEach()?

map() returns a brand-new array built from transforming each item, which is exactly why React uses it to turn data into UI elements. forEach() just loops and returns nothing, so it's not used for rendering lists.

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on React 18+ ยท Last updated August 2026