Operators
Operators — CS 111 Review.
Operators
Operators are the little symbols that actually do the work — combining values, comparing them, calculating new ones. Every move, every decision, and every UI update in a game runs through some operator.
Operator Categories
Click any category to see what it covers.
Operator
Category
Math
String
Boolean
Pick a category above to see its operators.
The Three Categories
- String Operations. Concatenation joins text with
+. Template literals embed values inside backticks:`HP: ${hp}`. You can pull out single characters by index:"wolf"[0]returns"w". Used for dynamic UI text, file paths, and NPC state labels. - Mathematical Operations. The basics —
+,-,*,/— plus modulo (%), which gives the remainder of a division. Modulo is surprisingly useful for game timing:frame % 60cycles once every second at 60fps. Used everywhere movement, physics, damage, and animation timing show up. - Boolean Expressions. Logical operators (
&&,||,!) combine true/false values. Comparison operators (===,>,<) test relationships between values. Together they drive AI decisions, collision detection, and any toggle in game state.
The Three Categories — Tabbed View
Click a category to switch tabs.
Mathematical Operators
Math operators handle anything where numbers change.
frame % 60 // modulo — great for timing events
health - 10 // subtraction — take damage
velocity * 2 // multiplication — accelerate
Used for movement, physics, gravity, damage, animation timing, and cooldowns. Anything that updates over time is built on math.
String Operators
String operators are for stitching text together and pulling parts out.
"Player " + name // concatenation
`Health: ${hp}` // template literal
"wolf"[0] // character access → "w"
Used for NPC state labels, sprite file paths, dynamic UI text, and dialogue.
Boolean Expressions
Boolean operators decide whether something is true or not.
health > 0 // comparison
state === "hostile" // equality
isAlive && isVisible // AND — both must be true
isPaused || isMenuOpen // OR — either is enough
!isAttacking // NOT — flip the value
Used for AI decisions, collision logic, game loop control, and input handling. Booleans are the switches that turn behavior on and off.
Quick Reference
Category
Operators
Game purpose
Math
+ - * / %Calculate movement, physics, timing
String
+ `${ }` []Build dynamic text and paths
Boolean
&& || ! === > <Make decisions and comparisons
Key Things to Remember
- Modulo (
%) returns the remainder.frame % 60 === 0fires logic exactly once per second at 60fps — perfect for timed events. ==vs===— always prefer===. It checks both value and type, so5 === "5"isfalselike you'd expect.&&short-circuits — if the left side is already false, the right side never runs. Useful for guards.- Be careful with
+on mixed types —"5" + 3gives"53", not8. Convert first.