开发者

how to write Or condition in javascript?

开发者 https://www.devze.com 2023-01-16 10:42 出处:网络
is it correct?- i开发者_开发百科f (expiryMonth == \"MM\" || expiryMonth == \"mm\") { Yes, that\'s correct. MDC (Mozilla Developer Center) has plenty of information about logical operators.Yes, that\'

is it correct?-

i开发者_开发百科f (expiryMonth == "MM" || expiryMonth == "mm") {


Yes, that's correct. MDC (Mozilla Developer Center) has plenty of information about logical operators.


Yes, that's correct. You may be able to avoid the use of || in this situation by using the toLowerCase() or toUpperCase() method on strings:

if (expiryMonth.toLowerCase() == "mm") {

or

if (expiryMonth.toUpperCase() == "MM") {

Of course, this would also match Mm and mM, as Tim points out in the comments.

  • toUpperCase()
  • toLowerCase()


You could eliminate the need for the or statement and just set expiryMonth to lowercase.

expiryMonth=expiryMonth.toLowerCase(); // You can also use toUpperCase();

Then run your if statement.

0

精彩评论

暂无评论...
验证码 换一张
取 消