Loading ...
Sorry, an error occurred while loading the content.

Re: JSLint doesn't catch function declarations inside conditional blocks

Expand Messages
  • Douglas Crockford
    ... Thanks. Please try it now.
    Message 1 of 2 , Aug 16, 2011
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "paulcrowder1979" <paul@...> wrote:
      >
      > This code fails because strict mode prohibits function declarations in conditional blocks like "switch" and "if" statements, but JSLint doesn't catch this. This is particularly difficult to track down since neither Chrome nor Firefox shows an error; it just fails to parse the code and continues as if it weren't even there.
      >
      > (function () {
      > "use strict";
      >
      > var i = 1;
      >
      > switch (i) {
      > case 1:
      > function thisFailsInStrictMode() {
      > // Function declarations can't appear in a conditional statement.
      > }
      >
      > thisFailsInStrictMode();
      >
      > break;
      > }
      >
      > alert("This code won't be reached.");
      > }());
      >

      Thanks. Please try it now.
    Your message has been successfully submitted and would be delivered to recipients shortly.