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

1126Re: 'variable' was used before it was defined

Expand Messages
  • Woomla
    Feb 10, 2010
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "demirozba" <baris@...> wrote:
      >
      > I am checking if a variable is defined or not, if it is not defined explicitly I am going to define it by doing:
      >
      > if ( typeof(aVariable) == 'undefined' ) {
      > var aVariable = value;
      > }
      >
      > Because the variable is not defined I get the JSLint advice that it is used before it was not defined, and that is exactly what I want.
      >
      > What is the best practice to overcome this?
      >


      Define the variable and give it an initial value of null or 'undefined'. Then
      you can test for that:

      var aVariable = null;

      ...

      if (aVariable === null) {
      aVariable = value;
      }
    • Show all 6 messages in this topic