I am looking for best practice on how I may write this function more efficiently.
var d = new Date(),
time = d.getHours(),
day = d.getDay();
if (day > 0 || day < 7){
if (time > 18 || time < 8){
// execute code
}
}
if
statements into one with the logical AND operator&&
, but I don't think the efficiency difference will be noticeable, if there is one at all. If you find your current code more readable, there's nothing wrong in keeping it as it is. \$\endgroup\$