Which is faster:
if (var == 'value')
or
if (/value/.test(var))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
if (a == 'b')will be faster thanif (/b/.test(a)), but they’re not identical calls.'something' == 'some'isfalse, whereas/some/.test('something')istrue.The only reason to change from one to the other would be if the other’s more appropriate. If you’re worried about speed, benchmark your script and check where the bottlenecks are before worrying about a specific
ifstatement.