You have to add an event onresize
to check , it will not check on resize of window with out any event listiner
window.addEventListener('onresize',function(){
if (window.innerWidth < 600) {
$( "#top-menu" ).hide(); //i think you just need this only
} else {
$( "#top-menu" ).show();
}
})