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

Test for space.

Expand Messages
  • Harry Whitfield
    var x = fred ; if (x == ) { // the string is a single space, not the empty string alert( x is a space ); } results in this error message: Error: Problem at
    Message 1 of 6 , Aug 8, 2010
    • 0 Attachment
      var x = "fred";
      if (x == " ") { // the string is a single space, not the empty string
      alert("x is a space");
      }

      results in this error message:

      Error:
      Problem at line 2 character 7: Use '===' to compare with ' '.

      if (x == " ") {

      Is this intentional?
    • Harry Whitfield
      var x = fred ; if (x == ) { alert( x is empty ); } no longer produces an error message.
      Message 2 of 6 , Aug 8, 2010
      • 0 Attachment
        var x = "fred";
        if (x == "") {
        alert("x is empty");
        }

        no longer produces an error message.
      • Douglas Crockford
        ... Thanks. Please try it now.
        Message 3 of 6 , Aug 8, 2010
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, Harry Whitfield <g7awz@...> wrote:
          >
          > var x = "fred";
          > if (x == " ") { // the string is a single space, not the empty string
          > alert("x is a space");
          > }
          >
          > results in this error message:
          >
          > Error:
          > Problem at line 2 character 7: Use '===' to compare with ' '.
          >
          > if (x == " ") {

          Thanks. Please try it now.
        • Harry Whitfield
          ... Fixed - Thanks. (x == ) now gives error message again (which is correct). Harry.
          Message 4 of 6 , Aug 8, 2010
          • 0 Attachment
            On 8 Aug 2010, at 21:27:17, Douglas Crockford wrote:

            > --- In jslint_com@yahoogroups.com, Harry Whitfield <g7awz@...> wrote:
            > >
            > > var x = "fred";
            > > if (x == " ") { // the string is a single space, not the empty string
            > > alert("x is a space");
            > > }
            > >
            > > results in this error message:
            > >
            > > Error:
            > > Problem at line 2 character 7: Use '===' to compare with ' '.
            > >
            > > if (x == " ") {
            >
            > Thanks. Please try it now.

            Fixed - Thanks.

            (x == "") now gives error message again (which is correct).

            Harry.
          Your message has been successfully submitted and would be delivered to recipients shortly.