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

Unexpected " error when concatenating empty string

Expand Messages
  • paulb777
    For the code : function foo() { var bar = + baz; } Error: Problem at line 3 character 13: Unexpected . var bar = + baz; Is this a jslint regression or
    Message 1 of 2 , Feb 12, 2011
      For the code :

      function foo()
      {
      var bar = "" + baz;
      }

      Error:
      Problem at line 3 character 13: Unexpected ''.

      var bar = "" + baz;


      Is this a jslint regression or new feature. If a feature, what is the rationale?

      Thanks,
      Paul
    • Douglas Crockford
      ... JSLint doesn t like to see as an operand to +, nor does it like to see 0 as an operand to +. If baz is a string, then var bar = baz; is smaller, faster,
      Message 2 of 2 , Feb 12, 2011
        --- In jslint_com@yahoogroups.com, "paulb777" <paulb777@...> wrote:
        > Error:
        > Problem at line 3 character 13: Unexpected ''.
        >
        > var bar = "" + baz;
        >
        >
        > Is this a jslint regression or new feature. If a feature, what is the rationale?


        JSLint doesn't like to see '' as an operand to +, nor does it like to see 0 as an operand to +. If baz is a string, then

        var bar = baz;

        is smaller, faster, clearer. If baz is not a string, then

        var bar = String(baz);

        is certainly less mysterious.
      Your message has been successfully submitted and would be delivered to recipients shortly.