The alert method is a property of the window object so there is no real difference between window.alert, this.alert, and just plain alert by itself. So that is just about it when it comes to using alert, just pass in what you want to log and it should alert out to you.
One way to go about looping is to create a for loop, while, or do while type loop. For this example I went with a while loop and did a trick that involves looping backward with an index number to zero when it comes to the expression that is used for the while loop to find out if the looping should stop or not. The reason why that works is because the number zero will evaluate to false when it comes to converting a number value to a boolean value, while any positive number will evaluate to true. As long as the value of the expression remains true the loop will continue.
Anyway when I open this file up in my web browser the value of i will start at 4 and loop back to zero, when zero is reacted the example stops. However for each loop an alert will happen with the string value that I am creating for the value that I am passing gto the alert function. So the alert does not happen once for the first value and then thats it, it would seem that it does pause the flow of things as each value of i, as well as n ends up being alerted.
When it comes to working with arrays there are many useful array prototype methods such as the forEach method, and the array map method just to name a few. For this example I went with a quick example that makes use of the array map method as a way to create a new array from a source array and assign that to the same variable. Again just like with the while loop example I get each value that I want alerted to me when this happens.
This might work out okay if a developer is just working something out, but is not going to leave it that way, but when it comes to using alert in an actual production app of some kind that can get very annoying. There are other ways to log what is going on where even if it is left in place, will not greatly effect the behavior of the application.
So lets take a quick look at a simple innerText example for displaying something.
I just need to get a reference to an element by one means or another such as with document.getElementById. Once I have a reference to an element I can then use that as a way to display a message. A method like this can then be used to display a message in a browser window without having an annoying dialog box pop up each time.
The prompt method might still come in handy now and then, but for the most part I would prefer to go with input elements, or some other means of gathering user input that will not delay the event loop.
Once I have my custom log method defined I can then use it anywhere in my project where doing so is needed.
The best thing about his though is that as a project grows I am passing all stuff that is to be logged to a custom method rather than just console.log. This way I can change what logging is in one place very easily. For example say I do not want anything logged to the console for a moment, to do so i just need to comment out one line rather then every instance of console.log throughout my code.
In real projects I often might use something like this, but it often will become something packed with additional features, many of which might be custom to the nature of the project. There is making it so the module name is part of what gets logged, along with additional information that might help with debugging. There are other features that come to mind such has having an argument that will serve as a way to only log if a given condition is true, and so forth.
Also when it comes to debugging there are a wide range of better options that are far more useful, even beyond that of just console.lof by itself.