开发者

how to write Or condition in javascript?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜