Home > Web Front-end > JS Tutorial > My React Journey: Day 2

My React Journey: Day 2

Patricia Arquette
Release: 2024-11-25 00:29:11
Original
960 people have browsed it

My React Journey: Day 2

The journey continues, and I’m loving every step! Today, I delved into Basic Operators (Arithmetic, Assignment, Logical, Comparison) and Control Structures (if/else, switch, loops). These concepts are foundational, yet so powerful for building logic in code. Here’s a quick recap of what I learned:

Operators
1. Arithmetic Operators
These are the building blocks for mathematical operations:

Addition
- Subtraction
/ Division
* Multiplication
** Exponentiation (used to find powers, e.g., 2 ** 3 = 8)
% Modulus (finds the remainder of a division, e.g., 5 % 2 = 1)

2. Assignment Operators
Used to assign or update values in a variable:

= Assigns a value. Example: a = 5
=, -=, *=, /=, %= These combine arithmetic and assignment.Example:

let a = 7;
a += 3; // a = a + 3
console.log(a); // Output: 10
Copy after login

**= Raises the variable to a power and assigns the result.

3. Comparison Operators
These compare two values and return a Boolean (true or false):

== Equal to: Compares values but not types.
!= Not equal: True if values are different.
=== Strict equal: Compares both value and type.
!== Strict not equal: Checks that both value and type are different.
>, <, >=, <= Greater than, less than, and their equals variants.

4. Logical Operators
Used to combine or manipulate Boolean values:

&& (Logical AND): Returns true only if all conditions are true.
|| (Logical OR): Returns true if any condition is true.
!(Logical NOT): Flips the Boolean value (!true becomes false).

Control Structures
1. if/else Statements
These are conditional blocks that execute code only when a condition is met. Example:

let age = 18;
if (age >= 18) {
  console.log('You are an adult.');
} else {
  console.log('You are a minor.');
}




</p>
<p><strong>2. Switch Statements</strong><br>
A cleaner alternative to multiple if/else blocks, often used for checking one value against multiple cases. Example:<br>
</p>

<pre class="brush:php;toolbar:false">let day = 'Monday';
switch (day) {
  case 'Monday':
    console.log('Start of the work week.');
    break;
  case 'Friday':
    console.log('Almost the weekend!');
    break;
  default:
    console.log('It’s just another day.');
}
Copy after login

3. Loops
Loops are used to execute a block of code repeatedly:

  • For Loop:
    Iterates a set number of times.

  • While Loop
    : Continues until a condition is false.

  • Do-While Loop
    : Executes at least once before checking the condition.

Final Thoughts
Today was packed with knowledge! These concepts might seem basic, but they form the backbone of any programming language.

Slow and steady wins the race, and I’m taking it one step at a time. Day 3 is already on my mind, and I can't wait to see what’s next.

Want to join me on this journey? Let’s learn together!

Stay tuned for Day 3!

The above is the detailed content of My React Journey: Day 2. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template