Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Translating JS into Perl

by ron.savage (Novice)
on Feb 18, 2009 at 22:22 UTC ( #744899=perlquestion: print w/replies, xml ) Need Help??
ron.savage has asked for the wisdom of the Perl Monks concerning the following question:

Hi Folks The JS in question is: unary = empty[ tagName ] || !!unary; where unary in an incoming function parameter and empty is a hash. What I don't get it the idiom !!unary. I'm thinking it could be null upon entry, so the first ! is causing it to be defined if necessary, and the second ! is reverting it to it's 'proper' value.

Replies are listed 'Best First'.
Re: Translating JS into Perl
by kyle (Abbot) on Feb 18, 2009 at 22:37 UTC

    In Perl, the "!!(value)" idiom normalizes "(value)" as a boolean. Many different values are considered true, and a few different values are considered false, but the result of "!!(value)" can be only one of two values.

    So yes, this will make an undef value into a defined false value, but it will also make some random true value into a single predictable true value.

    I don't know for sure that it means the same thing in JavaScript, but I'd be pretty surprised if it doesn't.

      $many x $thanx;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://744899]
Approved by GrandFather
[stevieb]: Torturing one of my dev RPis to turn four 5v stepper motors at the same time (via Parallel:: ForkManager for 50k degrees (a whole lot of full turns!). Let's see if it burns out or not.

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-03-22 22:10 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (286 votes). Check out past polls.