JavaScript Loops & Functions

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!

Topic 15: Logical Operators

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

Examples in Console:

Topic 16: Equality Operators

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
Best Practice: Always use === and !== to avoid unexpected behavior!

Example in Console:

Comparing PI (number) with "3.14" (string) using strict equality (===)

Topic 17: While Loops

While loops repeat code WHILE a condition is true

While Loop Structure:

while(condition){
  // code to repeat
}

Do-While Loop: Executes code at least once, then checks condition

Login System Example:

Try logging in with credentials:





Enter credentials and click Login...

When to use: When you don't know how many times to repeat (e.g., waiting for valid input)

Topic 18: For Loops

For loops repeat code a LIMITED number of times

For Loop Structure:

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++)

Examples in Console:

For vs While:
For loop: When you know how many times to repeat
While loop: When you don't know how many times to repeat

Topic 19: Functions

Functions are reusable blocks of code

Function Structure:

function functionName(parameter1, parameter2){
  // code to execute
  return value; // optional
}

Functions in Console:

Key Terminology:

Why use functions?
📄 loading...
Loading...