Add JavaScript Comparison Operators to Condition Statements

Part of the JavaScript & AJAX For Dummies Cheat Sheet

JavaScript uses comparison operators inside conditions to make numeric or alphabetical comparisons of variables to other variables or values. Using these operators, you can determine whether a variable is greater than, less than, or equal to another variable or value. You can also use combinations of these comparison operators.

Name Operator Example Notes
Equality == (x==3) Works with all variable types, including strings.
Not equal != (x != 3) True if values are not equal.
Less than < (x < 3) Numeric or alphabetical comparison.
Greater than > (x > 3) Numeric or alphabetical comparison.
Less than or equal to <= (x <= 3) Numeric or alphabetical comparison.
Greater than or equal to >= (x >= 3) Numeric or alphabetical comparison.
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus

SERIES
JavaScript & AJAX For Dummies Cheat Sheet

Advertisement

Inside Dummies.com