⚛️ 10 JavaScript Concepts for React Beginners – With Code Samples

PriyaPriya
3 min read

React is a powerful JavaScript library for building user interfaces. But before diving deep into React, you need a solid understanding of core JavaScript concepts that it heavily relies on. In this post, we’ll go over 10 essential JavaScript concepts every React beginner should know — complete with code samples.


📌 1. Variables: let and const

React apps rely on variables to manage UI state and component logic. Always prefer const unless you know the value will change.

const name = "React";
let counter = 0;

In React:

const [count, setCount] = useState(0);

📌 2. Arrow Functions

Arrow functions are common in React, especially in callbacks and functional components.

const add = (a, b) => a + b;

In React:

const handleClick = () => {
  console.log("Button clicked");
};

📌 3. Destructuring

Destructuring helps you write cleaner code when dealing with props or state.

const person = { name: "Alice", age: 25 };
const { name, age } = person;

In React:

const Welcome = ({ name }) => <h1>Hello, {name}</h1>;

📌 4. Spread Operator

The spread operator (...) is often used to clone or update state immutably.

const oldArray = [1, 2];
const newArray = [...oldArray, 3]; // [1, 2, 3]

In React:

setUser({ ...user, age: 30 });

📌 5. Array Methods: map, filter, reduce

React often renders lists using map.

const fruits = ["apple", "banana"];
const fruitList = fruits.map(fruit => <li key={fruit}>{fruit}</li>);

filter is useful for conditional rendering:

const activeUsers = users.filter(user => user.active);

📌 6. Conditional (Ternary) Operator

Used frequently in JSX to conditionally render components.

{isLoggedIn ? <Dashboard /> : <Login />}

Cleaner than using full if/else in render logic.


📌 7. Template Literals

Useful for dynamic strings in JSX or debugging.

const name = "React";
console.log(`Welcome to ${name}`);

In React:

<p>Hello, {`User ${userId}`}</p>

📌 8. Truthy/Falsy Values & Short-Circuiting

JavaScript treats some values as falsy (false, 0, null, undefined, '', NaN).

{user && <p>Welcome, {user.name}</p>}

📌 9. Objects and Arrays

React often manages complex state using objects or arrays.

const user = {
  name: "John",
  hobbies: ["reading", "coding"]
};

console.log(user.hobbies[0]); // reading

Used in state like:

const [user, setUser] = useState({ name: "", age: 0 });

📌 10. Understanding this, Scope, and Closures

React functional components avoid using this, but closures are critical in hooks.

function outer() {
  let count = 0;
  return function inner() {
    count++;
    return count;
  };
}

const counter = outer();
counter(); // 1

React useEffect or event handlers often use closures internally.


✅ Bonus: JSX is JavaScript

Remember: JSX is just syntactic sugar for React.createElement. So being fluent in JavaScript is key to mastering React.

const element = <h1>Hello</h1>; // Behind the scenes: React.createElement('h1', null, 'Hello')

🎯 Final Thoughts

React doesn’t replace JavaScript — it builds on top of it. As a beginner, investing time into these JavaScript fundamentals will make learning React smoother, more intuitive, and way more enjoyable.


Did I miss a concept you found useful while learning React? Drop a comment and let’s chat!
Want a printable PDF version of these concepts? Let me know and I’ll send you one.

0
Subscribe to my newsletter

Read articles from Priya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Priya
Priya