Loops

The basic meaning of a loop in programming is: A loop is a way to repeat a set of instructions multiple times, automatically.
Repeat tasks easily
Handle repetitive work with less code

for loop, while loop, do-while-loop
for of, for in loop

For loop

When you know how much time the code execute then for off loop used. For off loop easy to use example shown below:

for (let i = 0; i < 5; i++) {
  console.log("Count: " + i);
}

While loop

The loop excutes block of codes untill condition true.

let i = 0
while (i > 0 ) {
    i++
    console.log(i) }

Do While loop

In this type of loop code execute one time untill the condition false.

 let i = 0
 do {
     i++
     console.log(i)
 } while (i > 10);

For off loop

This type of loop in iterable values like in arrays

const fruits = ["apple", "banana",
 "cherry"];
for (let fruit of fruits) {
  console.log(fruit);
}

For in loop

This type of loop used in objects

const person = { name: "John", age: 30 };
for (let key in person) {
  console.log(key + ": " + person[key]);
}

Functions

A function is block or code that runs when it is called.
Functions helps us reuse code instead of writing it again and again, whenever we want to use we just call it.

function functionName(parameters) {
   // code to execute
}

Types of Functions

There are two main types of functions in any other programming language these are built-in-function and user-defined-functions.

function functionName(parameters) {
   // code to execute
}

User-define or built-in function

The built-in-function are the standards that was defined by language and these have the specific functions defined already and cannot use for own purposes. The user-defined-functions are built by user and could be used for personal purposes.

function functionName(parameters) {
   // code to execute
}

Some built-in functions

Some built-in functions which have specific meanings in js are as follows:
parseInt(), parseFloat(), isNaN(), isFinite()
push(), toUpperCase(), random()

Some user-defined-functions

Some built-in functions which have specific meanings in js are as follows:
parseInt(), parseFloat(), isNaN(), isFinite()
push(), toUpperCase(), random()

Naming Functions

A named function has a specific name that you can use to call it later.

function greet() {
  console.log("Hello, World!");
}
greet(); // Output: Hello, World!

Anonymous Functions

A named function has a specific name that you can use to call it later.

function greet() {
  console.log("Hello, World!");
}
greet(); // Output: Hello, World!

Arrow Functions

An arrow function is a shorter way to write anonymous functions.

const greet = () => {
  console.log("Hello from arrow function!");
};
greet(); // Output: Hello from arrow function!