عملگرهای ریاضی (Arithmetic) : این عملگرها برای انجام انواع عملیات محاسباتی ریاضی مورد استفاده قرار میگیرند. شرح این عملگرها در جدول ۱۶ آمده است:
جدول ۱۶: عملگرهای ریاضی جاوااسکریپت
عملگر
توضیحات
مثال
+ , - , * , / , %
جمع، تفریق، ضرب و تقسیم و باقیمانده
x = y+z , a = a*2, n = n/10
++,--
افزایش و کاهش به میزان یک واحد
x++, y--, ++z, --w
**
توان
x = y**2
عملگرهای انتساب (Assignment): برای اختصاص یک مقدار به یک متغیر از این عملگرها استفاده میشود. برخی از این عملگرها ساده و برخی ترکیبی هستند؛ یعنی علاوه بر انتساب، عمل دیگری را نیز روی عملوندها انجام میدهند. جدول ۱۷ مجموعه این عملگرها را نمایش میدهد.
جدول ۱۷: عملگرهای انتساب در جاوااسکریپت
عملگر
توضیحات
مثال
عبارت معادل
=
مقدار عملوند سمت راست (y)، درون عملوند سمت چپ (x) قرار میگیرد.
x = y
x = y
+=
حاصل جمع عملوندهای x و y درون عملوند سمت چپ (x) قرار میگیرد.
x += y
x = x + y
-=
حاصل تفریق عملوندهای x و y درون عملوند سمت چپ (x) قرار میگیرد.
x -= y
x = x – y
*=
حاصل ضرب عملوندهای x و y درون عملوند سمت چپ (x) قرار میگیرد.
x *= y
x = x * y
/=
خارج قسمت تقسیم عملوند x بر عملوند y درون متغیر سمت چپ (x) قرار میگیرد.
x /= y
x = x / y
% =
باقیمانده تقسیم عملوند x بر عملوند y درون متغیر سمت چپ (x) قرار میگیرد.
x %= y
x = x % y
**=
عملوند x را به توان عملوند y میرساند و نتیجه را درون متغیر x قرار میدهد.
x **= y
x = x ** y
صفحه ۲۰۴
عملگرهای مقایسهای (Comparison): این عملگرها برای مقایسه دو عملوند بهکار میروند.
مجموعه این عملگرها در جدول ۱۸ آمده است:
جدول ۱۸: عملگرهای مقایسهای
عملگر
توضیحات
== و ===
== برای بررسی تساوی دو عملوند از لحاظ مقدار و === برای تساوی دو عملوند از لحاظ مقدار و نوع
!= و !==
!= برای بررسی عدم تساوی مقدار دو عملوند و !== برای بررسی عدم تساوی مقدار و نوع دو عملوند
< , >
کوچکتر یا بزرگتر بودن عملوند اول نسبت به عملوند دوم
>= , <=
کوچکتر یا مساوی، بزرگتر یا مساوی
?
عملگر شرطی سهتایی که برای انتخاب بین دو مقدار بر اساس یک شرط استفاده میشود.
عملگرهای منطقی (Boolean): از عملگرهای منطقی برای ترکیب یا معکوس کردن شرایط استفاده میشود. این عملگرها امکان ترکیب عبارات منطقی را در شرایط مختلف فراهم میکنند. جدول ۱۹ عملگرهای منطقی جاوااسکریپت را معرفی میکند:
جدول ۱۹: عملگرهای منطقی
عملگر
توضیحات
&&
عملگر AND بررسی میکند که آیا هر دو عملوند صحیح هستند یا خیر.
||
عملگر OR بررسی میکند که آیا حداقل یکی از شرطها درست است یا خیر.
!
عملگر NOT وضعیت درست یا غلط بودن یک شرط را معکوس میکند.
صفحه ۲۰۵
Page 203
Arithmetic operators: these operators are used to do all kinds of mathematical calculation operations. The description of these operators is given in Table 16:
Table 16: JavaScript arithmetic operators
Operator
Description
Example
+ , - , * , / , %
Addition, subtraction, multiplication, division and remainder
x = y+z , a = a*2, n = n/10
++,--
Increasing and decreasing by one unit
x++, y--, ++z, --w
**
Power
x = y**2
Assignment operators: these operators are used to assign a value to a variable. Some of these operators are simple and some are compound; that is, besides assignment they do another operation on the operands too. Table 17 shows the set of these operators.
Table 17: Assignment operators in JavaScript
Operator
Description
Example
Equivalent expression
=
The value of the right operand (y) is put in the left operand (x).
x = y
x = y
+=
The sum of the operands x and y is put in the left operand (x).
x += y
x = x + y
-=
The difference of the operands x and y is put in the left operand (x).
x -= y
x = x – y
*=
The product of the operands x and y is put in the left operand (x).
x *= y
x = x * y
/=
The quotient of dividing the operand x by the operand y is put in the left variable (x).
x /= y
x = x / y
% =
The remainder of dividing the operand x by the operand y is put in the left variable (x).
x %= y
x = x % y
**=
Raises the operand x to the power of the operand y and puts the result in the variable x.
x **= y
x = x ** y
Page 204
Comparison operators: these operators are used to compare two operands.
The set of these operators is given in Table 18:
Table 18: Comparison operators
Operator
Description
== and ===
== checks the equality of two operands in terms of value and === checks the equality of two operands in terms of value and type
!= and !==
!= checks that the values of two operands are not equal and !== checks that the value and the type of two operands are not equal
< , >
Whether the first operand is smaller or larger than the second operand
>= , <=
Smaller than or equal, larger than or equal
?
The ternary conditional operator, used to choose between two values based on a condition.
Logical operators (Boolean): logical operators are used to combine or reverse conditions. These operators make it possible to combine logical expressions in different conditions. Table 19 introduces JavaScript's logical operators:
Table 19: Logical operators
Operator
Description
&&
The AND operator checks whether both operands are true or not.
||
The OR operator checks whether at least one of the conditions is true or not.
!
The NOT operator reverses the true or false state of a condition.