Javascript is very flexible with regards to checking for "null" values.(Javascript在检查“空”值方面非常灵活。)
I'm guessing you're actually looking for empty strings, in which case this simpler code will work:(我猜您实际上是在寻找空字符串,在这种情况下,这种简单的代码将起作用:)
if(!pass || !cpass || !email || !cemail || !user){
Which will check for empty strings ( ""
), null
, undefined
, false
and the numbers 0
and NaN
(它将检查空字符串( ""
), null
, undefined
, false
以及数字0
和NaN
)
Please note that if you are specifically checking for numbers it is a common mistake to miss 0
with this method, and num !== 0
is preferred (or num !== -1
or ~num
(hacky code that also checks against -1
)) for functions that return -1
, eg indexOf
)(请注意,如果您专门检查数字,则使用此方法会遗漏0
是一个常见错误,并且num !== 0
是首选(或num !== -1
或~num
(同样会检查-1
hacky代码) ))返回-1
函数,例如indexOf
))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…