* Brad Ediger wrote (13/10/06 17:42):
> AFAIK, JS delays casting values to types until they are needed (for
> example, a Boolean context for an if statement's condition).
>
> The || operator does not return a Boolean value; it returns the first
> value if it would evaluate to true in a Boolean context -- otherwise it
> returns the second value. These semantics ensure that you can use || in
> this way without breaking any of the assumptions you'd make about
> Boolean values. So the extra set of parentheses doesn't change the value.
>
> Note that all of the traditional Boolean OR semantics still apply if you
> evaluate the resulting expression as Boolean:
>
> {a: 3} || {} // ==> {a: 3} (would evaluate to true in Boolean context)
> null || {} // ==> {} (would evaluate to true)
> null || 0 // ==> 0 (would evaluate to false)
>
> Someone who knows more about the JS type system can correct me on some
> of the finer points.
I don't know more, but the spec is here:
http://www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf
Page 58 has the relevant info. In particular, it says this:
NOTE
The value produced by a && or || operator is not necessarily of type
Boolean. The value produced will always be the value of one of the two
operand expressions.
If you don't mind reading techy documentation, the spec is the best
place to find out about this sort of thing.
Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---