They are not bad practices, even because they are still in the language, I believe that we can say otherwise: "do not use Alert, confirm and prompt, because there are currently other ways to do that are more in line with the site layout and we have more control".
Why the layout of the site?
Because it is not possible to style the windows of these commands, they are generated by the engine in the browser, so it can get quite strange a alert
for example here in the layout of Stackoverflow. If you click on the "Flag" link you will see a window, which of course is much more complex than a simple alert
or any of the other commands, but you can see that the window is fully adhered to the layout of the site, because it is a form of window/modal/popup/Alert anything you want done with javascript/html/css code, that is, if you can leave it with the layou you want.
Why more control?
Following the same example above, from the link "Flag", it is possible to control the behavior of the window, for example change color by clicking on some option, open or window on this while it is still Abeta, etc. These and other behaviors would not be possible with the commands of your question, because as said, they are controlled by the browser engine, and the control over them is quite limited, so with the layout.
So you might say that it’s not good practice, but I prefer to think of "there are other better ways to do it".
One malpractice would make misuse of something, for example using the getElementsByTagName
, take all elements of the type div
and find one with the ID "test", and for that getElementByID
.
They are crude tools, very antiprofisisonal looking, should be restricted to use for debug.
– epx
@epx is actually the exact opposite. They were not created for debug and are erroneously used for this by developer laziness.
alert
you use when you want to create an alert,confirm
when you want to confirm something andprompt
when you want to request something; to debug you should use debug tools. These items are only no longer used because they do not allow customization.– Woss