Javascript Operator
array Python module |
ast Python module |
code Python module |
COM PHP module |
dis Python module |
exp |
io Python module |
JavaScript |
join |
Loops |
numbers Python module |
operator Python module |
os Python module |
PS PHP module |
Python functions |
re Python module |
sep |
SPL PHP module |
StackOverflow |
stat Python module |
string Python module |
Strings PHP module |
time Python module |
UI PHP module
Michael Zippo
04.11.2021
👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
The JavaScript operator + = adds two values ​​and assigns the result to a variable. This operator is called the addition assignment operator. This is more convenient than the normal variable = X + Y syntax.
A plus sign and an equal sign together? Is this a typo? In JavaScript, a side-by-side plus and equals sign has its own meaning. This is the JavaScript addition assignment operator.
In this tutorial, we are going to talk about what the JavaScript + = operator is and how it works. We will see an example of this operator in action to help you learn how to use it.
What is the JavaScript operator + =?
The JavaScript operator + = adds value to the right of the operator to the left variable. The resulting value is then assigned to the left variable. This operator is called the addition assignment operator
Either look at the syntax of this operator.
We have declared a JavaScript variable called "welcome" whose value is " Hello ". So we have added " Sophie. to this value. The addition assignment operator adds these two values ​​and assigns the result to the command variable " welcome "
Our code returns:.
This operator has two uses. It is used to add two numbers. It is also used to sum the values ​​of two strings.
The assignment operator is another way of saying:
Addition The assignment operator is a way to make your code easier to read. A + sign = is much clearer than writing "variable = x + y" add two values ​​and assign the result to a variable
You will often see the addition assignment operator in loops with a counter that keeps track of how many times the loop has been executed
JavaScript operator + =:. adding numbers
The addition operator adds two numbers together. Let’s create a program that counts how many times "The Count of Monte Cristo "appears in a list. This list contains the results of a book club" Book of the survey year .
We will start by defining an array JavaScript containing the names of the books. We will also declare a variable to know how many times the book we are looking for appears:
Next, we’ll write a JavaScript for loop that scrolls through this list and counts how many times "The count of Monte - Cristo " appears:
to cycle through the loops through the "books" list. For each book in the list, our program checks if the title is equal to "The Count of Monte Cristo". If so, we use the addition assignment operator to increment the value "count" by 1. Otherwise, nothing happens.
Once our loop has been executed, our program prints how many times the book has appeared on our list. Let’s try our code:
Our code counted how many times the book displays in the list
Our code counted how many times the book appears in the list
+ = JavaScript operator:. strings
The JavaScript + = operator can join two strings together. This operator is more convenient than the long "variable = x + y" syntax
For example, suppose you have a user’s first and last name in two strings. You can use the + = operator to combine these values ‚Äã‚Äãinto a single string.
Let’s create a program that checks for any pie starting with "B" in a list. If this pie starts with "B & rdquo ;, it needs to be added to a new string, otherwise nothing should happen.
We’ll start by defining a list and a string:
The variable" start_with_b "will contain all the cakes beginning with" B ". Initially, its value is" | ".
Next, we’ll create a for loop to iterate through each pie and check if each pie starts with "B":
We use the JavaScript startWith () method to check if each pie in our list starts with "B".
If a pie begins with "B", our if statement is executed. In the if statement, we declare a variable called "message". This adds "| " to the end of each cake name. We do this so that they appear separately in our chain.
Next we use the assignment operator to add the content of the "message" to the end of the "start_with_b" window variable
Either run our coded.
the alternative to joining two strings is to use the concatenation operator or the concat () method. to learn more About these methods, take a look at our Guide to concatenating of JavaScript.
l ’ addition assignment operator (+ =) adds a value to another value and assigns the resulting value to a variable. Often used to append values ‚Äã‚Äãto the end of a string or to append numeric values.
We hope this article has helped you to resolve the problem. Apart from Javascript Operator, check other array Python module-related topics.