Detailed explanations & code examples are in the JavaScript (.js) file
Click the { } button at the bottom right to view it
Open the browser console (F12) to see all outputs!
Logical operators combine or manipulate boolean values (true/false)
| Operator | Name | Description | Example |
|---|---|---|---|
| && | AND | Returns true if BOTH conditions are true | true && true = true |
| || | OR | Returns true if AT LEAST ONE condition is true | true || false = true |
| ! | NOT | Reverses the boolean value | !true = false |
Different ways to compare values in JavaScript
| Operator | Name | Description | Example |
|---|---|---|---|
| = | Assignment | Assigns a value to a variable | x = 5 |
| == | Equality | Compares values (ignores datatype) | 5 == "5" - true |
| === | Strict Equality | Compares values AND datatype | 5 === "5" - false |
| != | Inequality | Checks if values are NOT equal | 5 != 3 - true |
| !== | Strict Inequality | Checks if values OR datatype are NOT equal | 5 !== "5" - true |
=== and
!== to avoid unexpected behavior!
Comparing PI (number) with "3.14" (string) using strict equality (===)
While loops repeat code WHILE a condition is true
while(condition){
// code to repeat
}
Do-While Loop: Executes code at least once, then checks condition
Try logging in with credentials:
Enter credentials and click Login...
For loops repeat code a LIMITED number of times
for(initialization; condition; increment){
// code to repeat
}
initialization: Starting value (let i = 1)
condition: Continue while true (i <= 10)
increment: Change after each loop (i++)
Functions are reusable blocks of code
function functionName(parameter1, parameter2){
// code to execute
return value; // optional
}
Loading...