Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Operations with Assignment | Basic Operations
Introduction to JavaScript
course content

Conteúdo do Curso

Introduction to JavaScript

Introduction to JavaScript

1. Basic Concepts
2. Variables and Data Types
3. Basic Operations
4. Conditional Statements
5. Loops
6. Functions

bookOperations with Assignment

Readability in code is essential, and JavaScript offers ways to make your code more elegant. In this chapter, we'll explore operations with assignments, which can streamline your code.

JavaScript provides several assignment operators:

  • Addition Assignment (+=);
  • Subtraction Assignment (-=);
  • Multiplication Assignment (*=);
  • Division Assignment (/=);
  • Remainder (Modulo) Assignment (%=);
  • Exponentiation Assignment (**=).

Assignment operators are used to enhance code readability.

Consider the following example:

123
let a = 17; a += 5; console.log(a);
copy

This code is equivalent to the following:

123
let a = 17; a = a + 5; console.log(a);
copy

The expression a += 5 accomplishes the same as a = a + 5.

Let's look at other assignment operators and their default counterparts:

With AssignmentDefault
a += 6a = a + 6
a -= 6a = a - 6
a *= 6a = a * 6
a /= 6a = a / 6
a %= 6a = a % 6
a **= 6a = a ** 6
Choose the correct result:

Choose the correct result:

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 3
We're sorry to hear that something went wrong. What happened?
some-alt