Sometimes you may execute JS before its requirements are fully loaded.
For executing JS after the page is fully loaded we can use following methods.
document.onload = function Name()
Else you can use below method.
window.onload = function Name()