JavaScript Tutorial in Hindi #11 | While Loop in JavaScript (2025)
while
Loop
javascript
CopyEdit
let i = 0;
while (i < fruits.length) {
console.log(fruits[i]);
i++;
}
- ✅ Used when you're unsure of loop count ahead of time
🧠 When to Use Which?
Loop TypeUse When You Need... | |
for | Full control, early break , index access |
forEach() | Simple, readable iteration (no break) |
map() | To return a new transformed array |
filter() | To return a subset of the array |
find() | To get the first matching item |
for...of | Clean syntax with values only |
🎯 Pro Tip:
Mix them as needed! Many devs use for
loops in places where performance or control matters, and map
/filter
for functional, clean code.