javascript - what's more efficient? checking == or just mutating the variable? -


Imagine that I have a variable named X. Let's say I wanted to make X = true every 5 seconds. (It can either be true or false in the middle of this 5 seconds, but resets when up to 5 seconds).

Is it already true if the investigation is already correct, if not, to re-assign it to the right? Or just X = true?

In other words, who will run faster?

  if (x == wrong) {x = true; }  

versus

  x = true;  

On the one hand, the first program can not change the variable if it is not on the other hand, the second program does not need to check the equivalent of X; It is directly in the drive

  • It almost always does not matter. Write code that is easy to understand and maintain. Only customize it if necessary.
  • The best way to ensure this is to check
  • which may be fast depending on the browser.
  • Depending on whether the variables are generally true or usually false.
  • said that, I think that in most scenarios it will have to establish a variable without testing, it will be faster.

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -