I know that this is simple terminology, but I can’t get it via google searching… what is it called when the value of a variable being assigned passes through?
An example in php:
<?php
if($bob = 5){ echo 'The assignment came through as a truthy value!, bob now equals '.$bob.'!'; }
if($bob = false){ echo 'The assignment occurred again, but the value of the assignment is the value "false", so this if block will not be executed!. Bob now equals '.$bob.'!'; }
echo ' Finally, bob is a: '.(string) $bob;
?>
An example in javascript:
bob = bob || {};
In your first example, you’re using assignment as an expression; that is, the assignment statement returns the value assigned (this behavior is a common source of bugs; often people accidentally use
=instead of==in their condition).The second example is using the short-circuiting behavior of the
||operator.