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

1131Re: [jslint] Re: 'variable' was used before it was defined

Expand Messages
  • Jean-Charles Meyrignac
    Feb 10, 2010
      Or you could use something like:

      var foo = foo || "some value";

      as suggested on this mailing list starting at 5/27/2009.
      Of course, it won't work if your object is equal to false or zero.

      Check the discussion, a lot of variants have been suggested.


      On Wed, Feb 10, 2010 at 5:16 PM, Aseem <aseem.kishore@...> wrote:

      > Actually, if you're using this pattern to check if a user-specified option
      > is set or not, explicitly using "var" is not the way to go.
      > In IE, at a script level (i.e. per file, or per script block), if it sees a
      > "var" declaration during its parse phase (before execution), it will reset
      > the value of that variable if it already existed.
      > So better would be to simply do this:
      > /*global foo: true */
      > if (typeof foo === "undefined") {
      > foo = "some value";
      > }
      > By not declaring "var" and simply assigning foo, foo will automatically get
      > global scope.

      [Non-text portions of this message have been removed]
    • Show all 6 messages in this topic