Logo

dev-resources.site

for different kinds of informations.

Loops in JavaScript !!πŸ“šπŸ”„

Published at
8/10/2024
Categories
javascript
es6
frontend
beginners
Author
iamrazzakk
Categories
4 categories in total
javascript
open
es6
open
frontend
open
beginners
open
Author
10 person written this
iamrazzakk
open
Loops in JavaScript !!πŸ“šπŸ”„

What is Loop in JavaScript ?

Ans: Basically loop use for do repeatedly run a block of code - until a certain condition is met.

Types of Loops

For Loop

  • When to Use: When you know how many times you want to repeat something.

  • How It Works: You start with a counter, repeat code as long as the counter is less than a limit, and update the counter each time.

  • Example:

Image description

while Loop

  • When To use: When you don't know exactly how many times you need to repeat something, but you have a condition to check

  • *How It Works: *

  1. The condition is checked.

  2. If the condition is true, the code inside the loop is executed.

  3. The condition is checked again.

  4. Steps 2 and 3 repeat until the condition becomes false.

  • Example:

Image description

Do-While Loop

  • When To use: Similar to a while loop, but the code inside the loop always runs at least once.

  • *How It Works: *

  1. The code inside the do block is executed once before any condition is checked.

  2. After executing the code block, the while condition is evaluated.

  3. If the condition evaluates to true, the loop executes the code block again. If the condition evaluates to false, the loop terminates, and the program continues with the code that follows the loop.

  • Example:

Image description

For In Loop

  • When To use: The for...in loop helps you go through each item in an object or an array. It’s like checking each item one by one.

  • *How It Works: *

  1. The loop starts by creating a variable (often called key) to store the current property name.

  2. The loop checks if the current property exists in the object.

  3. If the property exists, the code inside the loop is executed.

  4. The loop moves to the next property.

  • Example:

Image description

For of Loop

  • When To use: When you want to loop through values of an array or other iterable.

  • *How It Works: *

  1. The loop creates a variable to hold the current value.

  2. The loop iterates over each value in the iterable object.

  3. The current value is assigned to the variable.

  • Example:

Image description

Note: If you Know more please share.

Mail: [email protected]

es6 Article's
30 articles in total
Favicon
Next-Generation Buttons: Implementing the Command Pattern through Web Components
Favicon
Hoisting: facing Temporal dead zone
Favicon
Learn javascript promises. Part 1 β€” What is a promise?
Favicon
Bootcamping 02: Named exports and default exports - does it really matter?
Favicon
Mastering Modern JavaScript: A Deep Dive into ES6 Function Creation and Best Practices
Favicon
Promises: The Ability to Write Asynchronous Code Using Javascript
Favicon
Exploring JavaScript's Modern Primitives: BigInt and Symbol
Favicon
JavaScript ES6 Release Notes: Unleashing the Power of Modern JavaScript
Favicon
WHY YOU SHOULD LEARN ES6
Favicon
Understanding ES6 API's
Favicon
Transpiler vs Polyfills
Favicon
JavaScript Spread Syntax: Expanding Arrays and Objects
Favicon
API Design and Debugging:A Comprehensive Guide for BeginersπŸš€
Favicon
Understanding the JavaScript Spread Operator (With Examples)
Favicon
A Comprehensive Guide to ES6 and Arrow Functions
Favicon
Controla tus promesa con JavaScript
Favicon
Sets
Favicon
Enhanced Object Literals
Favicon
Iteration Stament i.e for-of loop
Favicon
1.1 Ins & outs of ES6(JavaScript) Import with Realworld Example and Demo Project.
Favicon
Math Namespace & BigInt
Favicon
JavaScript - Destructuring Arrays & Objects [Live Doc]
Favicon
ES2015 (ES6) Tips, Tricks, Best Practices, and Code Snippet Examples for Your Day-to-Day Workflow
Favicon
Objects in JavaScript
Favicon
Intro to DSA & Big O Notation
Favicon
Execution Context & Call Stack
Favicon
Asynchronous programming in Javascript - Callbacks, Promises & Async Await
Favicon
Loops in JavaScript !!πŸ“šπŸ”„
Favicon
Array
Favicon
Functions

Featured ones: