basiccodingconcept.online

What Is an Operator?

Operators are special symbols that tell a computer to perform specific operations on data. They work like buttons on a calculator, where each symbol has one defined purpose. Each operator does something different, such as adding, comparing, or assigning values. The computer uses operators to perform specific operations by following the meaning of each symbol.

Types of Operators

 

What Are Arithmetic Operators?

Arithmetic operators are symbols that perform basic mathematical calculations on numbers or data. They tell the computer to calculate a result using mathematical operations.

Symbol Name Example Result
% Modulo 17 % 5 2
** Exponentiation 4 ** 2 16
/ Division 20 / 8 2.5
* Multiplication 6 * 7 42
Subtraction 9 – 4 5
+ Addition 12 + 8 20

06 · Operators — JavaScript Playground
06

Operators

Operators perform actions on values: arithmetic, comparison, and logical results that drive your logic.

JavaScript
Output

    

What Are Comparison Operators?

Comparison operators compare two values and return true or false. They produce a Boolean result by checking the relationship between two values.

Symbol Name Example Result
<= Less than or equal 7 <= 7 true
>= Greater than or equal 4 >= 9 false
< Less than 10 < 2 false
> Greater than 15 > 6 true
!== Not equal 8 !== 8 false
=== Strict equal 3 === 3 true

What Are Logical Operators?

Logical operators combine multiple conditions into a single expression. They evaluate Boolean values and return a Boolean result.

SymbolNameBehaviorExample!NOTFlips true to false, or false to true!falsetrue||ORTrue if at least one side is truefalse || truetrue&&ANDTrue only if both sides are truefalse && truefalse 

What Are Assignment Operators?

Assignment operators use the basic = operator to assign a value to a variable. They also include shorthand operators for common operations, such as adding or subtracting while assigning a value.

Symbol Name Same As Example
Decrement x = x – 1 stock–
++ Increment x = x + 1 stock++
/= Divide and assign x = x / n stock /= 2
*= Multiply and assign x = x * n stock *= 3
-= Subtract and assign x = x – n stock -= 4
+= Add and assign x = x + n stock += 10
Operators Quiz

Operators Quiz

Question 1 of 10 Score: 0
0%

Key Takeaways

  • Arithmetic operators do math using +, -, *, /, and %. The + operator also joins strings together.
  • Comparison operators use ===, !==, >, and < to compare values and return true or false.
  • Logical operators use &&, ||, and ! to combine conditions, while Shorthand operators like += make code cleaner.