当赋值包含无法被指定为变量值的条件时,它被称为什么?

发布于 2024-11-16 04:25:05 字数 507 浏览 4 评论 0原文

我知道这是简单的术语,但我无法通过谷歌搜索得到它......当被分配的变量的值通过时它被称为什么?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二手情话 2024-11-23 04:25:05

在第一个示例中,您使用赋值作为表达式;也就是说,赋值语句返回分配的值(这种行为是错误的常见来源;人们经常在条件中意外地使用 = 而不是 ==)。

第二个示例是使用 || 运算符的短路行为。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文