Firefox claims code after Return

Asked

Viewed 393 times

5

Situation

It was performing some maintenance functions on JS. And a certain function I placed a return in the midst of it, for the rest was no longer necessary.
On seeing from the comment the rest or delete, I kept the code there.
When reloading the page the console fires this message:

Syntaxerror: unreachable code after Return statement

Syntax error : code inaccessible after return instruction

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 keeping a code after the return?

Obs

Browser : firefox 40.0

  • You can post the code here?

  • In my view, there is no problem in keeping code after Return if it is part of the logic, now keeping unused code can be a big problem, imagine if something unexpected happens and does not run Return, the code will run unused snippet may cause problems.

  • Which browser did you use? used some stricter directive?

2 answers

6


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

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

  • 1

    Funny, MDN says it’s a Warning, not an Error.

  • @bfavaretto has the link? send it ... does it vary from browser?

  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return

  • So, apparently this Warning unreachable code after return statement started in Gecko 40, at least that’s what it says on mdn, so Webkit does not have this correct Warning ?

2

  • I always comment, it was only a doubt of test environment : D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.