JavaScript For Loop
A JavaScript for loop is a control flow statement that allows code to be executed repeatedly based on a condition. It consists of three parts: initialisation, condition, and increment/decrement.
for (statement 1 ; statement 2 ; statement 3){ code here...}
Statement 1: It is the initialisation of the counter. It is executed once before the execution of the code block.
Statement 2: It defines the testing condition for executing the code block.
Statement 3: It is the increment or decrement of the counter & executed (every time) after the code block has been executed.
Flow chart
Example code For Loop
JavaScript do...while Loop
A do...while loop in JavaScript is a control structure where the code executes repeatedly based on a given boolean condition. It's similar to a repeating if statement. One key difference is that a do...while loop guarantees that the code block will execute at least once, regardless of whether the condition is met initially or not.
Entry Controlled loops: In this type of loop, the test condition is tested before entering the loop body. For loops and While Loops are entry-controlled loops.
Exit Controlled Loops: In this type of loop, the test condition is tested or evaluated at the end of the loop body. Therefore, the loop body will execute at least once, irrespective of whether the test condition is true or false. The do-while loop is exit-controlled.
Example code while Loop
*Functions in JavaScript *
Functions in JavaScript are reusable blocks of code designed to perform specific tasks. They allow you to organise, reuse, and modularise code. It can take inputs, perform actions, and return outputs.
point 1. Code Resuability
point 2. Modularity
point 3. Readability
point 4. Maintainability
**Syntax**
function functionName(parameters) {
// function body
// ...
}
Function declaration
*Function calling *
As with variables, the identifier used when declaring a function acts as a symbolic name for a value. Referencing a function by identifier alone returns only the function object, and doesn't execute the function it contains:
`function myFunction() {
console.log( "My function has been executed." );
}
myFunction();
"My function has been executed."`
What is a function argument?
A function argument is a value that we pass to the function. The function parameter will represent the value. When I use parameters like name and last name, the values that I will pass, will be called arguments.






Top comments (0)