Sitemap

JavaScript -2

2 min readFeb 18, 2024

--

IF -Else Statements

You can use it to set a condition for your code run. I specific requirements are met, something is done; If they are not met, another action is taken. The switch statement which called as a block condition. The switch however allows you to choose which of several code blocks to run. The syntax of if-else statements in JavaScript is given below:

If(check ckondition){
// code that should be executed when the given condition is satisfied
}else{
// code that should be executed when the given condition is not satisfied
}

Loop in JavaScript

Get Janujah Sivarattinam’s stories in your inbox

Join Medium for free to get updates from this writer.

Most of the programming language include loops. They let run the code many time until the condition over. Loop can be created in variety of ways in JavaScript.

  1. The for loop : The most frequent method of creating a loop in JavaScript.
for (initialization expression; condition for the loop; updation after the loop) {
// code to be executed in loop
}

2. The while loop : Set a condition under the which loop will run.

// Initialization of the loop variable is done before the while loop begins
while(condition checking for the loop){
// 1. code to be executed in loop
// 2. updation of the loop variable
}

3. The do-while loop : Similar to the while loop loop, but it runs at-least one time before check the condition.

// Initialization of the loop variable is done before the do-while loop begins
do{
// 1. code to be executed in loop
// 2. updation of the loop variable
}while(condition checking for the loop);

There are two statements that are important in the context of loops:

  1. The continue statement : Skip parts of the loop if certain conditions are met.
  2. Break statement : Used to stop and exit the cycle when specific condition are met.

--

--