Orbit Reached
You have completed all mission contexts.
Readability is Key
You can chain 10 operators together on one line, but it makes the code unreadable. Break complex math into smaller variables so humans can understand it.
Using Parentheses ()
You can force the computer to do math out of order by wrapping it in parentheses. (10 + 5) * 2 forces the addition first, giving 30.
Operator Precedence
JS follows the order of operations (PEMDAS). 10 + 5 * 2 is 20, not 30, because multiplication happens before addition.
Nullish Coalescing (??)
This operator checks if something is missing. 'let name = inputName ?? "Guest"'. It means: Use inputName, but if they gave me null or undefined, use 'Guest' instead.
The Ternary Operator (?)
Itās a mini yes/no decision on one line. 'score > 50 ? "Pass" : "Fail"'. It means: If score > 50 is true, output Pass. Otherwise, output Fail.
String Operators
You already know '+' glues strings. But comparison operators work on text too! 'A' < 'B' is true because A comes first in the alphabet.
Short-Circuiting (||)
If JS sees an '||' and the first half is true, it skips the second half. It already found the one 'true' it needed to pass.
Short-Circuiting (&&)
If JS sees a '&&' and the first half is false, it doesn't even bother reading the second half. It already knows the whole thing fails. It saves processing time.
Logical NOT (!)
Putting an exclamation mark flips a boolean. If 'isRaining' is true, '!isRaining' becomes false. It is an instant reverse switch.
Logical OR (||)
The '||' operator is lenient. 'hasCash || hasCreditCard' means as long as ONE of the sides is true, the whole statement is accepted as true.
Logical AND (&&)
The '&&' operator forces multiple rules to be true. 'hasKey && isDoorUnlocked' means BOTH things must be true before you can enter.
Strict Not Equal (!==)
Just like equality, use the strict version. '!==' ensures the two items are completely different in value or data type.
Not Equal (!=)
The exclamation mark means 'NOT'. So '10 != 5' is asking 'Is 10 NOT equal to 5?'. The answer is true.
Strict Equality (===)
Triple equals is what professionals use. It checks if the value AND the data type are identical. 5 === '5' is false. Always use triple equals.
The Danger of Loose Equality (==)
Double equals checks if the values look similar, ignoring the data type. It thinks the number 5 and the string '5' are perfectly equal. This causes nasty bugs.
Greater/Less or Equal (>=, <=)
Adding an equals sign checks if it is bigger OR exactly the same. '10 >= 10' is true, whereas '10 > 10' is false.
Comparison: Less Than (<)
The alligator eats the bigger number. '10 < 5' returns false. You use these to check if a user is old enough or a score is high enough.
Comparison: Greater Than (>)
Compares two sides. '10 > 5' returns the boolean true. It asks a yes/no question of the data.
Compound Subtraction (-=)
Works exactly like addition. 'health -= 20' immediately removes 20 from the health variable. You can also do this with *= and /=.
Compound Assignment (+=)
Instead of typing 'cash = cash + 50', you can just type 'cash += 50'. It is a faster way to update a variable based on its own current value.
Decrement (--)
The opposite of increment. 'lives--' means 'subtract exactly 1 from the current lives'. Perfect for countdowns.
Increment (++)
Typing 'score++' is a shortcut. It means 'take the current score, and add exactly 1 to it'. We use this constantly in games and loops.
Exponentiation (**)
Double asterisk means 'to the power of'. 2 ** 3 means 2 * 2 * 2 (which is 8). It's a quick way to do heavy exponential math.
The Modulo Operator (%)
This is the remainder tool. 10 % 3 asks: 'If I divide 10 by 3, what is left over?' The answer is 1. It is perfect for determining if numbers are odd or even.
Arithmetic: Division (/)
Use the forward slash to divide. 10 / 2 gives 5. Remember, dividing by zero in JS doesn't crash the computer; it just returns the concept of 'Infinity'.
Arithmetic: Multiplication (*)
Use the asterisk symbol for multiplication. 10 * 5 gives 50. Essential for calculating areas, scaling graphics, or determining total costs.
Arithmetic: Subtraction (-)
Standard subtraction. 10 - 5 gives 5. Unlike addition, you cannot subtract strings. 'Hello' - 'World' will give you an error (NaN).
Arithmetic: Addition (+)
Just like regular math. 10 + 5 gives 15. If used with strings, it glues them together. It's the most common tool in your kit.
The Assignment Operator (=)
The equals sign doesn't mean 'these are equal'. It means 'take what is on the right, and put it into the box on the left'. It is a loading mechanism.
What are Operators?
Operators are the verbs of programming. If variables are the nouns (the objects), operators tell those objects to do somethingālike combine, subtract, or compare.
Lecture 03: Operator in Javascript
Total Duration: 1 hrs 58 mins 56 secs