In most cases, we should use =. We can use x = null only when detecting null/undefined, because we usually do not distinguish null from undefined, x = null is abbreviated as x = null | x = undefined.
The = comparison seems convenient, for example, 1 = '1', but it will bury hidden risks, such as the assumption that the type may be incorrect.
Example:
If (x = 10) x + = 5 www.2cto.com
If the input x is a string '10', the result of x is '123 '. In subsequent operations, the string '123' may be transformed to introduce hidden errors.
In addition, programmers may unconsciously rely on certain assumptions-for example, equal comparisons should be passed, that is, a = B, B = c, and a = c. However, the = of JavaScript is not passed. For example, 0 = '0', 0 = '', but '0 '! = ''.
Therefore, the = of JS is not the equals () of Java/C #, because the Java/C # language requires that equals () must be passed.
In short, for large-scale programming, the small convenience of = cannot be compared with the risk.
Suggestion:
Forget =, only use =. = A design error. It will try to perform type conversion (not java equal, it is well defined), The type conversion rules are not easy to remember. It also destroys the transmission.
Only === ,! =, You will feel a little comfortable writing javascript
Author: QQ101209442