JavaScript Compound Assignment With Augmented Subtraction
In JavaScript, the compound assignment with augmented subtraction operator is written as -= . It is used to subtract a value from a variable and assign the result to the variable. Here is an example of how it can be used:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
[/dm_code_snippet]
In the example above, the value of x is first set to 10. Then, the compound assignment with augmented subtraction operator is used to subtract 5 from x and assign the result (5) back to x . Finally, the value of x is logged to the console and it is output as 5.
You can also use the compound assignment with augmented subtraction operator to subtract a variable from another variable, like this:
In this example, the value of x is first set to 10 and the value of y is set to 5. Then, the compound assignment with augmented subtraction operator is used to subtract the value of y from x and assign the result (5) back to x . Finally, the value of x is logged to the console and it is output as 5.
Here are a few more examples of how the compound assignment with augmented subtraction operator can be used in JavaScript:
In the first example, the value of x is set to 10 and then 3 is subtracted from it using the compound assignment with augmented subtraction operator. The result (7) is then assigned back to x and logged to the console.
In the second example, the value of y is set to 20 and then 5 is subtracted from it using the compound assignment with augmented subtraction operator. The result (15) is then assigned back to y and logged to the console.
In the third example, the value of z is set to 100 and then z is subtracted from itself using the compound assignment with augmented subtraction operator. The result (0) is then assigned back to z and logged to the console.
Share this:
Recent Posts
- Angular js 531
- Express.js 176
- Guides 3,248
- Javascript 604
- Libraries 134
- Next.js 309
- node.js 454
- Python 2,658
- React js 472
- Tutorial 140
- Video 2,811
and Angular Angular.js Bottle django Express.js fastapi, flask Gatsby.js Guides javascript Keras Kivy Next.js node.js PyQt PySimpleGUI python PyTorch React react.js scikit-learn TensorFlow Tkinter video vite vite.js vue Vue.js with
Search code, repositories, users, issues, pull requests...
Provide feedback.
We read every piece of feedback, and take your input very seriously.
Saved searches
Use saved searches to filter your results more quickly.
To see all available qualifiers, see our documentation .
- Notifications
Not sure where to start?
Study group
Collaborate with peers in your dedicated #study-group channel.
Code reviews
Submit projects for review using the /review command in your #code-reviews channel
Built with Imba
freeCodeCamp Challenge Guide: Compound Assignment With Augmented Multiplication
Compound assignment with augmented multiplication.
Computers read from left to right. So, using the multiplication assignment operator means that the variable is multiplied with the number on the right, then the variable is assigned to the product. Like so:
IMAGES
VIDEO
COMMENTS
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window.
In this lesson we learn how to compound assignment with augmented subtraction. For example (myVar = myVar - 5) can be rewritten as (myVar -= 5) and it means...
Tell us what's happening: im trying to subtract like the example showed me but its not working with operator that was given any tips Your code so far var a = 11; var b = 9; var c = 3; // Only modify code below this …
Discover the magic of "-=" in JavaScript! Learn how augmented subtraction simplifies code and boosts efficiency effortlessly.
Compound Assignment With Augmented Subtraction. Like the += operator, -= subtracts a number from a variable. 1 myVar = myVar - 5; will subtract 5 from myVar. This can be rewritten as: 1 myVar -= 5; Discord. 1/4. 2/4.
In the example above, the value of x is first set to 10. Then, the compound assignment with augmented subtraction operator is used to subtract 5 from x and assign the result (5) back to x.Finally, the value of x is logged to the console and it is output as 5.. You can also use the compound assignment with augmented subtraction operator to subtract a variable from another variable, like this:
Look carefully at the example given in the exercise's description: you need to use it as a model. Also, there's something that's not supposed to be there in your code.
Compound Assignment With Augmented Addition. In programming, it is common to use assignments to modify the contents of a variable. Remember that everything to the right of the equals sign is evaluated first, so we can say: myVar = myVar + 5; to add 5 to myVar. Since this is such a common pattern, there are operators which do both a mathematical ...
Basic JavaScript - Compound Assignment With Augmented Subtraction. JavaScript. Kensic September 20, 2023, 4:31pm 1. Tell us what's happening: ... Compound Assignment With Augmented Subtraction. Link to the challenge: freecodecamp.org. freeCodeCamp.org. Learn to Code — For Free. pkdvalis September 20, 2023, 4:57pm 2. Kensic: let targetA = 5.
Like the += operator, -= subtracts a number from a variable. - Compound-Assignment-With-Augmented-Subtraction/README.md at main · Peterfrontenddev1/Compound ...
Follow along at:https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/*In this playlists numbering is corrected from Playlist 1 and we...
Specifically, the /= operator, known as "Compound Assignment With Augmented Division," simplifies the process of dividing a variable by another number. Traditionally, dividing a variable by a ...
Free Code Camp Material - To help you learn and walk-through step-by-step. JavaScript Algorithms and Data Structures SectionBasic Javascript Sub-Section Comp...
Compound Assignment With Augmented Subtraction problem. JavaScript. Rokit12 May 4, 2018, 11:12am 1. Tell us what's happening: ... Augmented Subtraction . Instead of a = a - 6; just do this a -=6; and same goes with others too : b -=15; c -=1; 1 Like. Rokit12 May 4, 2018, 11:38am 3. kindly help me write the whole code…it doesnt work for me ...
Compound Assignment With Augmented Multiplication. The *= operator multiplies a variable by a number. 1 myVar = myVar * 5; will multiply myVar by 5. This can be rewritten as: 1 myVar *= 5; Discord. 1/4. 2/4.
The pattern of operating on a variable and assigning it back to that variable is so common that there's a short-hand way of writing it. Instead of writing a = a + 3 you can just write a += 3.Same for all the other arithmetic operators.
Compound Assignment With Augmented Division. The /= operator divides a variable by another number. myVar = myVar / 5; will divide myVar by 5. This can be rewritten as: myVar /= 5; The /= operator divides a variable by another number. will divide myVar by 5 . This can be rewritten as:
Learn Basic JavaScript. Compound Assignment With Augmented Subtraction. For Teams Why Scrimba? Pricing. Log in. Learn to code with interactive scrims. Our courses and tutorials will teach you React, Vue, Angular, JavaScript, HTML, CSS, and more. Scrimba is the fun and easy way to learn web development.
Compound Assignment With Augmented Multiplication Hints Hint 1 Computers read from left to right. So, using the multiplication assignment operator means that the variable is multiplied with the number on the right, then the variable is assigned to the product. Like so: var c = 2; c *= 3; // Now, 'c' is equal to 6