`if (condition = value)` 是正确的比较语法吗? [英] Is `if (condition = value)` the correct syntax for comparison?

查看:32
本文介绍了`if (condition = value)` 是正确的比较语法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果if((hit.transform != transform) 表示if hit.transform is Not transform,那么我如何检查语句是否正确.if(hit.transform = transform) 似乎不起作用.

If if((hit.transform != transform) means if hit.transform is Not transform, then how do I check if the statement Is correct. if(hit.transform = transform) doesn't seem to work.

推荐答案

你需要两个等号才能相等

You need two equals signs for equality

if (hit.transform == transform)

请注意,这将允许各种隐式转换,因此您应该真正使用三个等号——身份相等或严格相等:

Note that that will allow all sorts of implicit conversions, so you should really use three equals signs—identity equality or strict equality:

if (hit.transform === transform)

请注意,单个等号是赋值.

Note that a single equals sign is assignment.

x = y;

现在 x 的值为 y.

Now x has the value of y.

你的陈述

if(hit.transform = transform)

将 hit.transform 赋值给 transform 的值,然后测试这个表达式的结果是否与 hit.transform 的新值相同,是否真实"

Assigns hit.transform to the value of transform, then tests to see if the result of this expression, which will be the same as hit.transform's new value, is "truthy"

这篇关于`if (condition = value)` 是正确的比较语法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆