Skip to main content

JavaScript Comparisons & Booleans

JavaScript Comparisons & Booleans is a core JavaScript concept covering javaScript Comparisons & Booleans: --8<-- "core-logic/arithmetic-operators.md" This topic is essential for academic learning, board exam preparation, and developing optimized real-world code.

What are Arithmetic Operators?

Arithmetic operators are used to perform mathematical calculations like addition, subtraction, and multiplication. They are the most basic building blocks of programming logic.

OperatorOperationDescription
+AdditionAdds two values together
-SubtractionSubtracts the right value from the left value
*MultiplicationMultiplies two values
/DivisionDivides the left value by the right value
%ModulusReturns the remainder after division

Note: While the basic behavior is the same across languages, how they handle things like "Integer Division" (e.g., 5 / 2) can vary.

Comparison Operators

OperatorDescription
==equal to (value only)
===equal value and equal type
!=not equal
!==not equal value or not equal type
>greater than
<less than
>=greater than or equal to
<=less than or equal to
?ternary operator

Strict Equality (===)

In JavaScript, == converts variable values to the same type before comparing. This is called Type Coercion. === does not convert type.

let x = 5;
x == "5"; // true (string "5" converted to number 5)
x === "5"; // false (number vs string)

Logical Operators

  • &&: logical and
  • ||: logical or
  • !: logical not

Conditional (Ternary) Operator

JavaSript also contains a conditional operator that assigns a value to a variable based on some condition.

Syntax: variablename = (condition) ? value1:value2

let voteable = (age < 18) ? "Too young":"Old enough";
Always use Strict Equality

To avoid bugs, always use === and !== instead of == and !=. It makes your code more predictable.

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir