What types of loops exist in JavaScript?
Experience Level: Junior
Tags: JavaScript
Answer
In JavaScript, there are three types of loops:
for
loopwhile
loopdo...while
loop
Here's an example of how each of these loops could be used:
// for loop example for (let i = 0; i < 10; i++) { console.log(i); } // while loop example let j = 0; while (j < 10) { console.log(j); j++; } // do...while loop example let k = 0; do { console.log(k); k++; } while (k < 10);
Related JavaScript job interview questions
What is a difference between var and let in JavaScript?
JavaScript JuniorWhat are the ES6+ features you use?
JavaScript JuniorWhat is an event loop in JavaScript?
JavaScript JuniorHow are the 'async' and 'await' keywords used in JavaScript?
JavaScript JuniorWhat is 'this' keyword in JavaScript?
JavaScript Junior