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

Re: [jslint] Why isn't !! OK?

Expand Messages
  • Jordan
    I don t understand why the logical test can t be: if ((event.charCode && launchIsKeyCode) || (!event.charCode && !launchIsKeyCode)) { You don t need to force a
    Message 1 of 6 , Feb 2, 2010
    • 0 Attachment
      I don't understand why the logical test can't be:

      if ((event.charCode && launchIsKeyCode) || (!event.charCode && !launchIsKeyCode)) {

      You don't need to force a boolean when doing a logical comparison test, and what you want is the opposite of xor - when both are true or both are false. For readability's sake, why not just state both conditions?

      - Jordan

      --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@...> wrote:
      >
      > It seems pellucid to me. It means "is the truthiness of charCode the same as the actual truth-value of launchIsKeyCode". In fact, I cannot think of a better way to express it. The only obvious variation is
      >
      > if (!charCode === !launchIsKeyCode)
      >
      > and that isn't exactly equivalent, since it would give a different answer if charCode were truthy and launchIsKeyCode were truthy but not a boolean true.
      >
      > M.
      >
      >
      >
      > ________________________________
      > From: Douglas Crockford <douglas@...>
      > To: jslint_com@yahoogroups.com
      > Sent: Tue, February 2, 2010 5:44:17 AM
      > Subject: Re: [jslint] Why isn't !! OK?
      >
      > --- In jslint_com@yahoogroups.com, "iain_dalton" <iain.dalton@> wrote:
      >
      > > var launchIsKeyCode = this.prefs.getBoolPref(this.kbLaunchNames.userIsKeyCode);
      > > var charCode = event.charCode;
      > > if ((!!charCode) === launchIsKeyCode) {
      > > return;
      > > }
      >
      > I have to confess, this code confuses me.
      > What is it intending to do? Could it be made clearer?
      >
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
      > [Non-text portions of this message have been removed]
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.