Operators
JavaScript operators are the symbols/keywords that perform actions on values: arithmetic, comparisons, logical flow, assignment, bitwise ops, and more.
In Bnlang, the operator tokens are identical across English and Bangla (e.g., +, ===, &&, ??, instanceof, in, typeof, delete, new, await, yield, void).
Quick Notes
+is addition and also string concatenation; unary+xcoerces to number.==does coercive equality; prefer===for strict equality.??returns right side only if left isnullorundefined(unlike||which treats many falsy values).&&=,||=,??=are logical assignment operators.yield(generator) andawait(async) are contextual.- Optional chaining
?.and spread/rest...are punctuators often called “operators.” Included here for completeness.
Operator Tables by Category
গাণিতিক (Arithmetic)
| অপারেটর | নাম | উদাহরণ | নোট |
|---|---|---|---|
+ | যোগ / স্ট্রিং জোড়া | 1 + 2, "a" + "b" | সংখ্যা যোগ বা স্ট্রিং concat |
- | বিয়োগ | 7 - 3 | |
* | গুণ | 4 * 2 | |
/ | ভাগ | 7 / 2 | ফ্লোট ফল; Math.floor ব্যবহার করে নামানো যায় |
% | ভাগশেষ | 7 % 3 | remainder |
** | ঘাত | 2 ** 3 | exponentiation |
+x | ইউনারি প্লাস | +"42" | number‑e coercion |
-x | ইউনারি মাইনাস | -"5" | negation/coercion |
ইনক্রিমেন্ট/ডিক্রিমেন্ট
| অপারেটর | নাম | উদাহরণ | নোট |
|---|---|---|---|
++x | প্রিফিক্স ইনক্রিমেন্ট | ++i | বাড়িয়ে নতুন মান ফেরত |
x++ | পোস্টফিক্স ইনক্রিমেন্ট | i++ | পুরনো মান ফেরত, পরে বাড়ে |
--x | প্রিফিক্স ডিক্রিমেন্ট | --i | |
x-- | পোস্টফিক্স ডিক্রিমেন্ট | i-- |
তুলনা (Comparison)
| অপারেটর | নাম | উদাহরণ | নোট |
|---|---|---|---|
=== / !== | কঠোর সমতা/অসমতা | a === b | coercion নেই |
== / != | শিথিল সমতা/অসমতা | "5" == 5 | coercion হয়—এড়ানো ভালো |
<, <=, >, >= | সম্পর্ক অপারেটর | a < b | স্ট্রিং তুলনায় lexicographic |
লজিক্যাল ও নালিশ (Logical & Nullish)
| অপারেটর | নাম | উদাহরণ | নোট |
|---|---|---|---|
&& | AND | a && b | short‑circuit |
| ` | ` | OR | |
! | NOT | !x | booleanize |
?? | Nullish coalescing | x ?? y | কেবল null/undefined হলে y |
&&=, ` | =, ??=` | Logical assignment |
অ্যাসাইনমেন্ট (Assignment)
| অপারেটর | নাম | উদাহরণ |
|---|---|---|
= | অ্যাসাইন | x = 5 |
+=, -=, *=, /=, %= | গাণিতিক অ্যাসাইন | x += 2 |
**= | ঘাত অ্যাসাইন | x **= 2 |
<<=, >>=, >>>= | শিফট অ্যাসাইন | x <<= 1 |
&=, ^=, ` | =` | বিটওয়াইজ অ্যাসাইন |
বিটওয়াইজ (Bitwise)
| অপারেটর | নাম | উদাহরণ |
|---|---|---|
& | AND | a & b |
| ` | ` | OR |
^ | XOR | a ^ b |
~ | NOT | ~x |
<< | বাম শিফট | x << 2 |
>> | ডান শিফট (sign‑prop) | x >> 1 |
>>> | জিরো‑ফিল ডান শিফট | x >>> 1 |
রিলেশনাল/টাইপ (Relational/Type/Other)
| অপারেটর | নাম | উদাহরণ | নোট |
|---|---|---|---|
typeof | টাইপ নির্ণয় | typeof x | ফল স্ট্রিং |
instanceof | কন্সট্রাক্টর সম্পর্ক | x instanceof C | প্রোটোটাইপ‑চেইন |
in | প্রপার্টি আছে? | "name" in obj | প্রোটোটাইপসহ |
delete | প্রপার্টি মুছুন | delete obj.x | |
void | undefined করুন | void expr | মান ফেলে দেয় |
new | কন্সট্রাক্ট ইনস্ট্যান্স | new C() | |
await | প্রমিস অপেক্ষা | await p | async‑এ |
yield, yield* | জেনারেটর ফলানো | yield x | gen‑এ |
কন্ডিশনাল, কমা, অপশনাল/স্প্রেড
| অপারেটর | নাম | উদাহরণ | নোট |
|---|---|---|---|
?: | টার্নারি | cond ? a : b | এক্সপ্রেশন‑লেভেল if |
, | কমা | (a = 1, b = 2) | বাম চালিয়ে ডান ফল |
?. | অপশনাল চেইন | obj?.prop() | পাংচুয়েটর |
... | স্প্রেড/রেস্ট | [...xs], function f(...a){} | পাংচুয়েটর |
উদাহরণ:
const user = { name: "Mamun" };
const label = user?.name ?? "Guest";
let x = 2; x **= 3; // 8
const list = [1, 2]; const more = [...list, 3]; // [1,2,3]
if (a > 0 && b > 0) print("both positive");
Precedence (Common Highlights)
- Highest → lowest (selected):
()call/member →new→**→ unary (! ~ + - typeof void delete await) →* / %→+ -→ shifts (<< >> >>>) → comparisons (< <= > >= in instanceof) → equality (== != === !==) → logical AND&&→ logical OR||→ nullish??→ conditional?:→ assignment (=,+=, …&&= ||= ??=) → comma,. **is right‑associative; most arithmetic is left‑associative. Ternary?:is right‑associative.- Mixing
??with||/&&needs parentheses.
Notes
- BigInt works with most arithmetic/bitwise ops but cannot mix with Number (e.g.,
1n + 1→ TypeError). typeof null === "object"(historical quirk). Arrays/dates/regex show"object".inchecks across the prototype chain; for own‑props useObject.hasOwn(obj, key).- Spread
...and optional chaining?.are punctuators commonly treated as operators.