For loop question

Why the word "grasshopper "is only written once?Not many many times?

It depends what your code looks like.

This will print out each letter separately. The loop runs once for each letter of the string.

for (let letter of 'grasshopper') {

This will print out 'grasshopper' once (because there is 1 item in the array.)

for (let word of ['grasshopper']) {

This will print out 'grasshop' 11 times (once for each letter of 'grasshopper').

for (let letter of 'grasshopper') {


1 Like

ok,thank you so much.