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

Type inconsistency: string and number. (variable reuse)

Expand Messages
  • bartman1c
    I have many applications that use a single variable to go through both objects and arrays, never at the same time, I understand the variable(in this example
    Message 1 of 2 , Jun 13 4:27 PM
      I have many applications that use a single variable to go through both
      objects and arrays, never at the same time, I understand the variable(in
      this example "x") becomes string for objects and number for arrays but I
      can't understand the problem of reusing it.

      I get errors like this one
      Error: Problem at line 3 character 8: Type inconsistency: string and
      number. for (x = 0; x < arr.length; x = x + 1) { list_a.push(x); }
      my example code:
      var obj = {a: 1, b: 2}, arr = [1, 2], x, list_o = [], list_a = []; for
      (x in obj) { if (obj.hasOwnProperty(x)) { list_o.push(x); } } for (x =
      0; x < arr.length; x = x + 1) { list_a.push(x); }


      [Non-text portions of this message have been removed]
    • Douglas Crockford
      ... See http://tech.groups.yahoo.com/group/jslint_com/message/2241
      Message 2 of 2 , Jun 13 5:47 PM
        --- In jslint_com@yahoogroups.com, "bartman1c" <bartman1c@...> wrote:

        > I have many applications that use a single variable to go through both
        > objects and arrays, never at the same time, I understand the variable(in
        > this example "x") becomes string for objects and number for arrays but I
        > can't understand the problem of reusing it.


        See http://tech.groups.yahoo.com/group/jslint_com/message/2241
      Your message has been successfully submitted and would be delivered to recipients shortly.