Course

Assignment Operators

Loading...

In this lesson, you'll learn about in JavaScript and how they are used to assign and manipulate values in variables.

Assignment Operators

An assignment operator assigns a value to its left operand based on the value of its right operand.

Basic Assignment Operator

Would you believe me if I told you that you not only know what an assignment operator is, but that you've been using it this whole time? The simplest form of an assignment operator is the equal sign used for assigning values to variables:

const number = 5;

This right here is an assignment operator.

Compound Assignment Operators

We can also combine the assignment operator with one of the arithmetic operators to perform an operation and assignment in one step:

let number = 5;

number += 5; // the same as number = number + 5;
number -= 5; // the same as number = number - 5;
number *= 5; // the same as number = number * 5;
number /= 5; // the same as number = number / 5;
console.log(number);

String Concatenation with Assignment

The addition assignment can also be used with strings! Let me show you:

let string = 'Hello';
string += ', I am John.';
console.log(string);

That's it when it comes to assignment operators—you're basically a pro at them! 😊

Loading...

0 Comments

"Please login to view comments"

glass-bbok

Join the Conversation!

Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.

Upgrade your account
tick-guideNext Lesson

'if' Statement