I wanna alert the message. Example 1 is working but Example 2 isn't. Everything else like localStorage.setItem
or console.log
aren't working in Example 2 too. Why?
Example 1
$(document).on('unload', alert('Reloaded!'))
Example 2
$(document).on('unload', function (){
alert('Reloaded!');
});