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

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

问题描述

如果 if((hit.transform!= transform)表示如果hit.transform为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。

您的陈述

if(hit.transform = transform)

将hit.transform分配给transform的值,然后测试以查看此e的结果xpression,与hit.transform的新值相同,是truthy

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天全站免登陆