Fork me on GitHub

JSLint Error Explanations

JSLint will hurt your feelings. It's time to make them better!

Unexpected 'else' after 'return'

When do I get this error?

JSLint (prior to July 2013) will throw the "Unexpected 'else' after 'return'" error when it encounters an else block following an if block that contains a return statement. Here's some example code:

Why do I get this error?

This error is raised to highlight a completely pointless piece of code. If execution enters the if block, the function will return. There will be no way execution can enter the else block. Therefore, you can simply omit the else block and place its contents directly after the if block. Here's the above snippet again, without the error:

James Allardice

This article was written by James Allardice, an enthusiastic young JavaScript developer at Global Personals (we're looking for developers so please apply). He is passionate about writing clean, maintainable JavaScript and uses JSHint every day to help achieve this.

You can follow him on Twitter, fork him on GitHub and find him on Google+.

Proceeds generated by this site are donated to help advance other open source projects

comments powered by Disqus