0

In javascript, if (true || false) results in true, but the question is whether the compiler will evaluate the second statement if the first is true. In my case, I want to know if an array has changed, so I believe I have two options: compare the lengths of the arrays (what was and what is now) and compare if the array values are different.

I think the first option requires less work. If (first || second) { give me deleted values, and give me added values }

1
  • It doesn't, which can actually be useful for assigning a fallback: falsy_value || "fallback" // returns "fallback"; truthy_value || "fallback" // returns truthy_value; Commented Dec 8, 2022 at 11:00

1 Answer 1

3

No, it does not

first() || second()

function first() {
  console.log('first')
  return true
}

function second() {
  console.log('second')
  return false
}

Sign up to request clarification or add additional context in comments.

3 Comments

Please look for duplicates prior to answering. There are over 2.4 million JavaScript questions on SO. Surely someone else has answered this question before?
@Ivar Why is it bad to answer to a duplicate?
Because we want to keep all the high quality information in one place. So that when people want more details/a different view on the matter can just check the other answers. So that when something in the language changes, it only needs to be updated in one place and not across thousands of questions. --> Why are some questions marked as duplicate? If a question that is closed as a duplicate prevents new answers from being accepted, you might argue that it shouldn't have been answered to begin with.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.