Here's a clear comparison of the main operators in C++ vs. JavaScript, covering categories like arithmetic, assignment, comparison, logical, bitwise, and special operators.
🔢 Arithmetic Operators
Operation | C++ | JavaScript | Notes |
---|
Addition | + | + | JS + also used for string concatenation |
Subtraction | - | - | |
Multiplication | * | * | |
Division | / | / | In JS, division of integers can produce floats |
Modulus | % | % | |
Exponentiation | — | ** | JS only |
Increment | ++ | ++ | Pre/post |
Decrement | -- | -- | Pre/post |
📝 Assignment Operators
Operation | C++ | JavaScript | Notes |
---|
Assignment | = | = | |
Add & assign | += | += | |
Subtract & assign | -= | -= | |
Multiply & assign | *= | *= | |
Divide & assign | /= | /= | |
Modulo & assign | %= | %= | |
Exponent & assign | — | **= | JS only |
Bitwise & assign | &= , etc. | &= , etc. | Both support |
🔍 Comparison Operators
Operation | C++ | JavaScript | Notes |
---|
Equal to | == | == (loose) / === (strict) | JS === also checks type |
Not equal to | != | != (loose) / !== (strict) | Same as above |
Greater than | > | > | |
Less than | < | < | |
Greater or equal | >= | >= | |
Less or equal | <= | <= | |
⚙️ Logical Operators
Operation | C++ | JavaScript | Notes |
---|
AND | && | && | Short-circuit |
OR | || | || | Short-circuit |
NOT | ! | ! | |
🧠 Bitwise Operators
Operation | C++ | JavaScript | Notes |
---|
AND | & | & | |
OR | | | | | |
XOR | ^ | ^ | |
NOT | ~ | ~ | |
Left Shift | << | << | |
Right Shift | >> | >> (arith) / >>> (logical) | JS adds logical shift >>> |
🧪 Special Operators
Operation | C++ | JavaScript | Notes |
---|
Ternary | ?: | ?: | Same syntax |
Type checking | typeid , dynamic_cast | typeof , instanceof | Different mechanisms |
Member access | . / -> | . / [] | JS uses [] for dynamic keys |
Scope resolution | :: | — | C++ only |
new operator | new | new | JS also uses class syntax |
delete operator | delete | delete | In C++: memory; in JS: object property |
Comma operator | , | , | Rarely used in JS |
sizeof | sizeof | — | C++ only |
Optional chaining | — | ?. | JS only |