Skip to the workspace
Pebellslearn by building
Introduction to React Native  ›  Capstone Project

The JavaScript You Need

JavaScript Basics 14 minReact Native code relies on a small set of modern JavaScript features: const and let, arrow functions, destructuring, array methods like map and filter, modules, spread and async/await.

react native / The JavaScript You Need

Explore each scene at your own pace.

01 · The rule

The rule

The JavaScript You Need

React Native code is modern JavaScript from top to bottom. You do not need to know the whole language, but a handful of features appear on every screen of Sprout. If any of them look strange, the rest of the course will too.

The rule

Know five moves: const, arrows, destructuring, map, and await.

Here they are in one small piece of Sprout:

const plants = [
  { id: 'p1', name: 'Fern', everyDays: 3 },
  { id: 'p2', name: 'Cactus', everyDays: 14 },
];

const label = ({ name, everyDays }) => `${name}: every ${everyDays} days`;

const labels = plants.map(label);

async function loadPlants() {
  const response = await fetch('https://example.com/plants.json');
  return response.json();
}
  • const and let. Use const for names that are never reassigned and let for those that are. Avoid var.
  • Arrow functions. (x) => x * 2 is a short function. Components and event handlers are often arrows.
  • Destructuring. ({ name, everyDays }) pulls fields out of an object. Props arrive this way: function PlantCard({ name }).
  • map and filter. Arrays of data become arrays of results. plants.filter(p => p.everyDays < 7) keeps thirsty plants.
  • async and await. Network calls return promises. await waits for the result without freezing the app.

Two more you will see constantly: modules (import and export) to split code into files, and the spread operator ... to copy an object with a change, as in { ...plant, name: 'Boston fern' }.

On the styling side, you need only a little CSS knowledge: names like padding, margin, color and Flexbox. React Native borrows those ideas but writes them in JavaScript objects, which a later section covers.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.