News for hackers. Stuff that matters.
Re:Reverse Engineering One Line of JavaScript by CrystalLangUser on Friday July 14, 2017 @07:10AM (#14768906)
Why is !! useful? Asking as a ruby programmer.
Re:Reverse Engineering One Line of JavaScript by drusepth on Friday July 14, 2017 @07:28AM (#14768979)
Because Ruby doesn't have a to_boolean method. !! is used to convert "truthy" or "falsy" values [0] into true boolean true or false values.

For example,

    def user_signed_in?
      !!current_user
    end
This returns "true" or "false", instead of a (truthy) User object or a (falsy) nil.

[0] https://gist.github.com/jfarmer/2647362

Re:Reverse Engineering One Line of JavaScript by asherkin on Friday July 14, 2017 @07:23AM (#14768961)
It is a shorthand method of casting to a boolean value - C didn't have a true bool type until "recently" (but did have the concept of truthiness, where true is `is not 0`), so many projects and libraries use `#define TRUE 1`, and #define FALSE 0` or some similar variant.

So rather than write `foo ? TRUE : FALSE` or being more explicit `(foo != 0) ? 1 : 0`, you can just do `!!foo`.

Re:Reverse Engineering One Line of JavaScript by sethrin on Friday July 14, 2017 @07:24AM (#14768966)
It's a quick cast to a boolean.