+ 5

Difference between alert() and window.alert()

Can some one explain me the difference between this two as they work exaclty the same way.

4th Apr 2018, 6:08 PM
Mitali
Mitali - avatar
4 Respostas
+ 9
window in JS is a global object, that means you can access it anywhere throughout your code. So, alert() becomes a global method / function. Therefore, you can call alert function of window object as window.alert() or alert(). The choice is upto you!
4th Apr 2018, 6:13 PM
777
777 - avatar
+ 3
They both perform the same functuon though personally, I prefer alert()
9th Nov 2019, 10:21 AM
Anthony Kwesi Saah
Anthony Kwesi Saah - avatar
4th Apr 2018, 6:11 PM
Bartosz Pieszko
Bartosz Pieszko - avatar