Contenido del Curso
Introduction to JavaScript
Introduction to JavaScript
3. Performing Operations in JavaScript
Understanding Assignment OperatorsMathematical Operations in JavaScriptAssignment Operators in JavaScriptIncrement and Decrement OperatorsChallenge: Variable Operations PracticeComparison Operators in JavaScriptLogical Operators ExplainedChallenge: Compare Variables in JavaScriptConcatenating Strings in JavaScriptChallenge: Build Sentences with JavaScript
4. Controlling Program Flow with Conditional Statements
5. Looping Through Data in JavaScript
Assignment Operators in JavaScript
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:
let a = 17; a += 5; console.log(a);
This code is equivalent to the following:
let a = 17; a = a + 5; console.log(a);
The expression a += 5
accomplishes the same as a = a + 5
.
Let's look at other assignment operators and their default counterparts:
With Assignment | Default |
---|---|
a += 6 | a = a + 6 |
a -= 6 | a = a - 6 |
a *= 6 | a = a * 6 |
a /= 6 | a = a / 6 |
a %= 6 | a = a % 6 |
a **= 6 | a = a ** 6 |
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 3. Capítulo 3