There is no problem with your code.. run this snippet
function hello() { alert('Hello'); }
Hello
and if you want to alert this on window load. change your code like this way
(function(){ alert('hello') })();