- Object/Oriented JavaScript
- Stoyan Stefanov
- 291字
- 2021-08-13 19:25:51
Operators
Operators take one or two values (or variables), perform an operation, and return a value. Let's check out a simple example of using an operator, just to clarify the terminology.
>>> 1 + 2
3
In this code:
+
is the operator- The operation is addition
- The input values are
1
and2
(the input values are also called operands) - The result value is 3
Instead of using the values 1
and 2
directly in the operation, you can use variables. You can also use a variable to store the result of the operation, as the following example demonstrates:
>>> var a = 1; >>> var b = 2; >>> a + 1
2
>>> b + 2
4
>>> a + b
3
>>> var c = a + b; >>> c
3
The following table lists the basic arithmetic operators:


When you type var
a =
1;
this is also an operation; it's the simple assignment operation and =
is the simple assignment operator.
There is also a family of operators that are a combination of an assignment and an arithmetic operator. These are called compound operators. They can make your code more compact. Let's see some of them with examples.
>>> var a = 5; >>> a += 3;
8
In this example a += 3;
is just a shorter way of doing a = a + 3;
>>> a -= 3;
5
Here a -= 3;
is the same as a = a - 3;
Similarly:
>>> a *= 2;
10
>>> a /= 5;
2
>>> a %= 2;
0
In addition to the arithmetic and assignment operators discussed above, there are other types of operators, as you'll see later in this and the following chapters.
- JasperReports for Java Developers
- ERP沙盤模擬教程
- PPT設(shè)計實用教程
- CorelDRAW服裝設(shè)計實用教程(第四版)
- 中文版3ds Max 2016實用教程
- Vue.js快速入門
- UI功夫:PC和APP界面設(shè)計全流程圖解
- Plone 3 Intranets
- 音樂制作7天速成:Cubase編曲教程
- TopSolid Wood軟件設(shè)計技術(shù)與應(yīng)用
- 跨境電商:速賣通搜索排名規(guī)則解析與SEO技術(shù)
- 構(gòu)筑敏捷的開發(fā)團(tuán)隊:微軟Visual Studio 2010實戰(zhàn)兵法
- 選擇的藝術(shù):Photoshop圖像處理深度剖析(第3版)
- Photoshop CS6淘寶美工完全實例教程(全視頻彩色版)
- Photoshop CC 從入門到精通