While and for loops in JavaScript allow code to be repeatedly executed. The while loop executes code as long as an expression is true, and the do-while loop always executes code at least once. The for loop initializes a counter, tests a condition, and iterates the counter in each compact statement.