Q:

Is it faster to store window.location.href in a const to do several comparisons or check it directly?

Is it faster to store the window.location.href in a const to check if contains several strings, 
   const fullUrl = window.location.href;

 function checkUrlContains() {
   return fullUrl.indexOf("string1") > 1 || fullUrl.indexOf("string2") > 1  || fullUrl.indexOf("string3") > 1 || fullUrl.indexOf("string4") > 1
 }

or to check directly the window.location.href?
     function checkUrlContains() {
   return window.location.href.indexOf("string1") > 1 || window.location.href.indexOf("string2") > 1  || window.location.href.indexOf("string3") > 1 ...
 }

Thank you

A:

Sometimes the "thin" books are the best ones.  Such as, The Elements of Programming Style.  In which you will read:
"Don't 'diddle' code to make it faster -- find a better algorithm."

But also:  "don't assume that an algorithm is 'too slow' unless you can prove by actual profiling measures that it is too slow and where it is.  In your case, that source-code change probably won't make any measurable difference in performance, but it just might make your code harder to "instantly understand" by the next programmer who follows in your footsteps.  The only time (these days) when you should seriously be concerned about such things is when profiling results prove that this-or-that is a true "hot spot."  Otherwise, just write code as clearly and obviously as you can, and of course be very certain that it works!

