XOR operator in javascript

How to predicate every character  in a string is number (0-9)?

normal way 1: validate by regular express

normal way 2: use parseInt() function

normal way 3: use isNaN() function

There are some other method also can do such checking, for example, check every character by loop etc.

We also can use XOR operator to do such work:


Exchange the value of tow variable

In normal way, we have to declare third variable to help  do such exchange work like below:

XOR operator can do it easily without third variable:

 Predicate tow int variable are same


Tagged with:
Posted in Javascript

Leave a Reply


Related Posts