JAVASCRIPT Tutorial

Assignment Operators

Purpose: Assign values to variables.

Steps:

  1. Use the equal sign (=) to assign a value to a variable:
let name = "John Doe";
  1. Use compound assignment operators to perform operations on a variable while assigning it a new value:
  • +=: Add a value
  • -=: Subtract a value
  • *=: Multiply by a value
  • /=: Divide by a value
  • %=: Modulo (remainder)
let count = 5;
count += 2; // Equivalent to count = count + 2;
  1. Value Assignment:
  • Variables are containers for values.
  • let keyword creates a variable.
  • Assignment operator assigns a value to the variable.

Example:

// Create a variable called "age" and assign it the value 25.
let age = 25;

Assignment Operators

What are they?

Assignment operators are used to assign values to variables.

How to use them:
  1. Equal sign (=): Use the equal sign to assign a value to a variable. Example: let name = "John Doe";
  2. Compound assignment operators: These operators perform an operation and then assign the result to the variable. Examples:
    • +=: Add a value
    • -=: Subtract a value Example: let count = 5; count += 2; // Equivalent to count = count + 2;

Key Tip:

  • Value assignment means giving a variable a value.
Example:
// Assign the value 25 to the variable "age".
let age = 25;