Sep 27, 2025
This lecture covers JavaScript operators, conditional statements, and how to use them in code to perform calculations and make decisions based on conditions.
//
./*
and */
.+
(add), -
(subtract), *
(multiply), /
(divide).%
is the modulus operator, returning the remainder after division.**
is the exponentiation operator (e.g., a ** b
is a to the power of b).++
) increases a variable by 1, decrement (--
) decreases by 1.++a
) changes value before use; postfix (a++
) changes after use.=
assigns a value to a variable.+=
, -=
, *=
, /=
, %=
perform the operation and assign the result (e.g., a += 4
is a = a + 4
).==
compares values, !=
checks for inequality.===
and !==
compare both value and data type (strict comparison).<
, <=
, >
, >=
compare numerical values.&&
(AND): returns true only if both conditions are true.||
(OR): returns true if at least one condition is true.!
(NOT): inverts the truth value.if
checks a condition and executes code if true.else
runs code if the if
condition is false.else if
checks additional conditions if previous if
or else if
are false.condition ? expr1 : expr2
) returns expr1
if the condition is true, else expr2
.switch
statement selects code to execute based on the value of an expression.case
represents a possible value; break
exits after a match; default
runs if no match.alert()
displays a message to the user.prompt()
asks the user for input and returns the value.prompt()
to get a number and check if it is a multiple of 5 or 3 (using %
).prompt()
and if-else
to assign grades based on score ranges.=
, +=
, etc.).==
, ===
, !=
, etc.).&&
, ||
, !
).if
, else
, switch
).condition ? value1 : value2
).switch
statement and explore MDN documentation (developer.mozilla.org) for further learning.