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

Re: [jslint] Just got confused with the `?` operator

Expand Messages
  • Felix E. Klee
    On Tue, Feb 5, 2013 at 11:17 PM, george_weilenmann ... Exactly not. I m a C programmer for more than 20 years, and I m well versed with
    Message 1 of 8 , Feb 5, 2013
    • 0 Attachment
      On Tue, Feb 5, 2013 at 11:17 PM, george_weilenmann <abyssoft@...>
      wrote:
      > This is more of an error on the part of the knowledge of the developer

      Exactly not. I'm a C programmer for more than 20 years, and I'm well
      versed with its operator precedence, which is similar to that of
      JavaScript. I frequently use the `?` operator, and without any issues.

      I just wanted to point out what happened to me today. That's all.
    • douglascrockford
      ... Thanks. Please try it now.
      Message 2 of 8 , Feb 5, 2013
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Felix E. Klee" wrote:
        > /*jslint devel: true */
        >
        > (function () {
        > 'use strict';
        >
        > var isOneWayFlight = true, i;
        >
        > for (i = 0; i < isOneWayFlight ? 1 : 2; i += 1) {
        > console.log(i);
        > }
        > }());
        >
        > Instead, the runtime enters an infinite loop. It outputs: 0, 1, 2, ...
        >
        > Correct version of the for statement, doing what I want:
        >
        > for (i = 0; i < (isOneWayFlight ? 1 : 2); i += 1) {
        > console.log(i);
        > }


        Thanks. Please try it now.
      • george_weilenmann
        Nice compromise. Works great and indeed improves readability.
        Message 3 of 8 , Feb 5, 2013
        • 0 Attachment
          Nice compromise. Works great and indeed improves readability.

          --- In jslint_com@yahoogroups.com, "Felix E. Klee" wrote:
          >
          > Well, today I'm not in good shape, and I expected the following code to
          > output just one zero. The code passes JSLint.
          >
          > /*jslint devel: true */
          >
          > (function () {
          > 'use strict';
          >
          > var isOneWayFlight = true, i;
          >
          > for (i = 0; i < isOneWayFlight ? 1 : 2; i += 1) {
          > console.log(i);
          > }
          > }());
          >
          > Instead, the runtime enters an infinite loop. It outputs: 0, 1, 2, ...
          >
          > Correct version of the for statement, doing what I want:
          >
          > for (i = 0; i < (isOneWayFlight ? 1 : 2); i += 1) {
          > console.log(i);
          > }
          >
          > That's just FYI.
          >
        • Felix E. Klee
          ... So quick - thanks! :-)
          Message 4 of 8 , Feb 7, 2013
          • 0 Attachment
            On Wed, Feb 6, 2013 at 3:47 AM, douglascrockford <douglas@...> wrote:
            > Please try it now.

            So quick - thanks! :-)
          Your message has been successfully submitted and would be delivered to recipients shortly.