I’ve got a JavaScript that uses this notation to make sure an object is initialized:
MyObject = MyObject || {};
I understand what it does, namely checking wether MyObject is anything, if not assigning an empty object to MyObject. I don’t really know all the internals of JS that well, so I don’t see how a logic comparison could be used in an assignment.
How does it work? Is there any other languages that allows this?
Depends on the language.
For example, in Ruby, you could use this style.
But in PHP, you could not use this style, because in PHP, the Logical Operators always returns a boolean value (true/false).
Conclusion:
If the Logical Operators always return a boolean value, then you could not use this style.
If the Logical Operators returns the first value when first value evaluates true otherwise return the second value, then you could use this style.