当赋值包含无法被指定为变量值的条件时,它被称为什么?
我知道这是简单的术语,但我无法通过谷歌搜索得到它......当被分配的变量的值通过时它被称为什么?
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;
?>
javascript 中的示例:
bob = bob || {};
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 || {};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在第一个示例中,您使用赋值作为表达式;也就是说,赋值语句返回分配的值(这种行为是错误的常见来源;人们经常在条件中意外地使用
=
而不是==
)。第二个示例是使用
||
运算符的短路行为。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.