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

Re: array destructuring

Expand Messages
  • Douglas Crockford
    ... No, which is why you should avoid it.
    Message 1 of 6 , Aug 2, 2010
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, Mark Volkmann <r.mark.volkmann@...> wrote:
      >
      > Just learned something new! This works in Rhino 1.7. See the line with
      > the comment below.
      >
      > function assert(condition) {
      > if (!condition) print('assertion failed'));
      > }
      >
      > function getValues() {
      > return ['text', 19, true];
      > }
      >
      > var [s, n, b] = getValues(); // Array destructuring!
      >
      > assert(s === 'text');
      > assert(n === 19);
      > assert(b);
      >
      > I can't find this in the ECMAScript 3 spec. Is this a standard
      > JavaScript feature?

      No, which is why you should avoid it.
    • 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 2 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 3 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 4 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 5 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.