So Many Operators! JavaScript operators are symbols or keywords used to perform operations on variables and values. They allow you to manipulate data and make decisions in your JavaScript code. You have already used the typeof
keyword operator and the =
assignment of value symbol, but there are a lot more operators! In this section, we will focus on Arithmetic, Comparison, and Logical Operators.
1. Arithmetic Operators¶
These operators perform basic mathematical operations, for numeric calculations, and also to join strings together.
Arithmetic Operators with Strings:

Concatenation with
+
Operator: The most common arithmetic operation with strings is concatenation, achieved using the+
operator. When used between strings, it concatenates or joins them. For example,"Hello " + "World"
results in"Hello World"
. 
Other Arithmetic Operators: Operations like

,*
,/
, etc., on strings typically result inNaN
(Not a Number), as these operations don't have a logical string equivalent. For example,"Hello"  "World"
results inNaN
.
2. Comparison Operators¶
Comparison operators compare values and return a Boolean (true
or false
). They are used to make decisions and control the flow of your code. You will study flow control in the next module.
Comparison Operators with Strings:

Alphabetical Ordering: Comparison operators (
<
,>
,<=
,>=
) are used to compare strings based on standard lexicographical ordering, using Unicode values. This means strings are compared alphabetically, and character by character. For example,"Apple" < "Banana"
evaluates totrue
because"Apple"
comes before"Banana"
in alphabetical order. "A" comes before "B" in the alphabet and in Unicode.Unicode is a universal character encoding standard that provides a unique number for every character, regardless of the platform, program, or language. This comprehensive system is designed to represent text in all the written languages of the world, as well as many symbols, emojis, and historic scripts. Unicode covers a vast range of characters and assigns each one a code point, which is a number in the format U+XXXX, where "XXXX" represents a hexadecimal value. For instance, the Unicode value for the uppercase letter "A" is U+0041 and "B" is represented by the code point U+0042. This standardization allows for the consistent encoding, representation, and handling of text, ensuring that digital text is accessible and consistent across different systems and devices. JavaScript strings are Unicodebased, allowing them to include characters from virtually any writing system.

Equality Operators: The
==
and===
operators can be used to check if two strings are exactly the same. For instance,"Hello" === "Hello"
results intrue
. 
Case Sensitivity: It's important to note that these comparisons are casesensitive, meaning
"a"
and"A"
are considered different (with"A"
typically coming before"a"
in Unicode order).
In summary, while arithmetic operations with strings are limited to concatenation, comparison operators open up a broad range of possibilities, allowing for alphabetical sorting and ordering based on Unicode values. This flexibility makes string manipulation in JavaScript both powerful and convenient.
3. Logical Operators¶
Logical operators are used to combine or manipulate Boolean values. They include AND (&&
), OR (
), and NOT (!
) to make logical decisions in your code.
Now let's look at some code examples that combine many of these operators:
JAVASCRIPT
Pseudocode For A Practice Problem¶
Objective: Write JavaScript code to evaluate a combined condition using arithmetic, comparison, and logical operators.

Initialize Variables: Declare two variables,
x
andy
, and assign them integer values. Example:let x = 5; let y = 7;

Define an Arithmetic Operation: Choose an arithmetic operation for
x
. It could be squaring it, doubling it, etc. Example: Squarex
. 
Define a Comparison Operation: Choose a comparison operation for
y
. It could be checking ify
is greater than, less than, or equal to a certain value. Example: Check ify
is greater than 10. 
Combine with Logical Operator Use a logical operator (
&&
or
) to combine the conditions from steps 2 and 3. Example: Use logical AND (&&
) to combine the conditions. 
Create the Final Expression: Write the final expression that combines the arithmetic operation on
x
, the comparison operation ony
, and the logical operator. Example:(x * x < 30) && (y > 10)

Store and Display the Result: Store the result of the expression in a variable, and display or log the result. Example:
let result = (x * x < 30) && (y > 10); console.log(result);

Commenting: Add a comment describing what the code is checking. Example:
// Check if x squared is less than 30 and y is greater than 10.
Answer: