Firefox complains of code after the return

5

Situation

I was performing some maintenance on JS. And a certain function put a return in the middle of it, because the rest was no longer necessary. In seeing the comment on the rest or delete, I kept the code there. When reloading the page the console launches this message:

  

SyntaxError: unreachable code after return statement

     

Syntax error: unreachable code after return statement

Code

function ajustaTela(){
    jQuery('.data').datepick();
    return;

    if(jQuery(document).innerWidth() < 1050){
        jQuery("#panel-header #panel-header-content #menu_header li").css({'padding':'6px 5px'});
    }else{
        jQuery("#panel-header #panel-header-content #menu_header li").css({'padding':'6px 10px'});
    }

    jQuery('span.adicionar_favoritos').css('margin-left', ((jQuery('span.adicionar_favoritos').parents('div.panel_title').width() / 2)-15) + 'px');

    jQuery('.data').datepick();

    makeHeaderFixedSize();
}

Doubt

What possible problems can I have in maintaining a code after return ?

Obs

Browser: firefox 40.0

    
asked by anonymous 10.11.2015 / 15:20

2 answers

6

The syntax error already breaks the code and this is a problem. This error means " Look, here is dead code (it will never run) after return . Remove it before someone thinks it is good for anything."

The ideal is to remove the dead code instead of commenting it, as some other programmer might want to test it.

    
10.11.2015 / 15:25
2

I'm sorry for the statement because I did not quite understand your reason for leaving the code, but the mistake is to leave something after the return, which will never be used, regardless of language.

Two suggestions and you allow me:

1) Comment the whole code after the return and leave an explanation of why; 2) or delete the entire code after the return.

This link talks about a compiled language and why remove, JavaScript is interpreted language, but it gives a good explanation why removing

    
10.11.2015 / 23:54