Beginner

React Native variables and values

Name and store information so the program can use and change it later.

Chapter goal: Name and store information so the program can use and change it later.

Simple explanation

A variable is a labelled box. The label is the variable name, and the value inside is the information your program needs to remember.

In React Native, this chapter is about giving useful names to values and understanding when a value may change. Start with the idea above. Then connect each symbol to a value or action in the example.

Do not try to remember every symbol. First ask what data the program has, what it does with that data, and what result it creates. Technical words become easier when you connect them to those three questions.

Why this topic is important

Variables connect almost every instruction. Without them, a program cannot remember a name, score, price, setting, or result. In React Native, the syntax may look different from other languages, but the thinking skill transfers: name the data, choose the right operation, and make the next step obvious.

When to use it

Use variables for form input, game health, shopping totals, loading states, configuration, and calculated results.

Example code

const price = 5;
const quantity = 3;
const total = price * quantity;
console.log(`Total: ${total}`);

Line-by-line explanation

What the output means

Total: 15

The output is evidence that the program followed the instructions. If your result is different, read from the first line and write down how each value changes. That is debugging, not failure.

Mistake example

const x = 5;
const y = 3;
const z = x * y;
console.log(z); // unclear names

The calculation works, but names such as x, y, and z hide what the values mean. A beginner or teammate must guess the purpose of each variable.

Fixed version

const price = 5;
const quantity = 3;
const total = price * quantity;
console.log(`Total: ${total}`);

The corrected version uses price, quantity, and total, so the calculation explains itself.

Common mistakes

Warning: Change one part at a time. If you change many lines together, it becomes harder to learn which change caused the result.

Real use cases

Practice exercise

  1. Change the price and quantity, then calculate the new total.
  2. Rename each variable so its purpose is clear.
  3. Create one value that must not change.

Tip: If the exercise feels too large, complete only steps 1 to 3. Small working code teaches more than a large unfinished project.

Mini quiz

  1. Which side of = is calculated first?
  2. What is the difference between a name and its value?
  3. Which variable name is clearer: x or totalPrice?

How to read AI-generated code

Do not copy AI code first. Read it like a detective. Find the data, follow the changes, and locate the final output. Ask AI to explain a line only after you have made your own guess.

React Native reading check

Find the component inputs (props), changing values (state), event handlers, and effects. An effect that fetches data must also handle loading, failure, and a component that leaves the screen.

Before you move on

Next topic

Next, learn operators and expressions. Before opening it, explain this chapter out loud in under one minute.

Open the interactive lesson →
← React Native syntax and data typesReact Native operators and expressions →