6 Essential JavaScript Basics You Must Master Before Learning React

React is highly in demand for web development. Before we dive into React, we must have a strong understanding and grasp of JavaScript.
For most of us who started with JavaScript, after a few months of learning, we forget the basics or the most important topics we must learn and remember for learning React. So, in this article, we will discuss the 6 most important things we need to know about JavaScript to start our React journey.

  1. Understanding the let, const variables:
    We must know how to declare variables, and most importantly, how to do it using let and const. When we declare a variable that will
    not change, we use const.
    When we know that the variable might change, we use let to declare our variable.
const name = "James Bond";
let age = 30;
age = 42;
console.log(name, "Age:", age)

2. How to declare a condition:
When we want to execute our code based on some condition, we use if, else if, and else. We must have a clear understanding of this and practice it because conditions are everywhere. If some condition is fulfilled, do this; otherwise, do that.
We write the if keyword, then write a condition inside () and if that is true, we go inside {} where we specify the tasks to perform.
If the statement is not true, we can use else if or else statements based on our needs. For the condition, we can compare using ( >, <, ===, !==, >= and <= ). For multiple conditions: if all conditions need to be matched, we use &&, and for any one condition to be true, we use ||.

if (age <= 30) {
    console.log("Young James")
}
else if (age === 42) {
    console.log("Adult James")
}
else {
    console.log("Old James")
}

3. Array:
We must know how to write an array.
For example:

const numbers = [4, 8, 12, 16, 87, 45, 67];

And understand the indexing of an array. The position of every element in an array is called the index. Indexing starts at 0. So, for our array above, the index of 4 is 0, and the index of 12 is 2.
We can also find the length of an array using the array name and the .length property.

4. Loops:
We must know how to write a loop. When we need some tasks to run multiple times or continuously, we use loops. The basic loop is the for loop. Here, we declare a variable with let and give it an initial value, then give ;, specify a condition, then give another ; and write an increment or decrement operation. As long as the condition is true, the code will run as a loop.

const numbers = [4, 8, 12, 16, 87, 45, 67]
console.log(numbers.length);

for (let i = 0; i < numbers.length; i++) {
    number = numbers[i];
    console.log(number)
}

5. Function:
How to write a function. When we learn React, we will see that everything starts with a function, so it’s mandatory
to learn how to write a function. There are multiple types of functions, but a basic function starts with the keyword
function followed by the name of the function. It can take parameters, and at the end, if we expect some output, we use the return keyword. We also have to call the function, or it will not work.

function multiply(age, number) {
    const multiplication = age * number;
    return multiplication;
}
const result = multiply(age, number); // age=42, number= 67
console.log(result)

6. Object:
How to write an object. What is an object? When we declare a variable with multiple properties, we write it as an object.
For example, if I ask what type of car James Bond uses, the answer requires different properties. So we write it as an object.
We can also access any property using the .nameOfTheProperty.

const car = {
    name: "BMW",
    color: "Black",
    price: 1000000
}
console.log(car.price)

Leave a Comment