DEV Community

[Comment from a deleted post]
Collapse
 
vasilvestre profile image
Valentin Silvestre

It's like the Null Coalescing Operator from PHP : php.net/manual/en/language.operato...

A common misconception is that a ||= b is equivalent to a = a || b, but it behaves like a || a = b

Here's a link explaining in Ruby : rubyinside.com/what-rubys-double-p...

Collapse
 
vasilvestre profile image
Valentin Silvestre

Stop liking my comment !
It's false, it's not a Null coalescing.

Ruby :
a || = b

PHP equivalent :
$a = $a != null ? $a : $b;

Or in "pseudocode" :
If 'a' is not null
'a' is equal to 'a' (itself)
else
'a' is equal to 'b'