0

Is the following function ambiguous in javascript?

equals(o) {
    return (this.x == o.x) 
        && (this.y == o.y);
}

That is, because it's spread across two lines, do I need to move the && to the line above? What are the rules for when I need to be concerned about spreading a statement across multiple lines?

Trisped
  • 5,705
  • 2
  • 45
  • 58
David542
  • 104,438
  • 178
  • 489
  • 842
  • [https://stackoverflow.com/questions/29154339/is-it-safe-to-split-long-javascript-if-conditions-into-multiple-lines](https://stackoverflow.com/questions/29154339/is-it-safe-to-split-long-javascript-if-conditions-into-multiple-lines)? Your syntax is fine and readable. – sean-7777 Jan 20 '22 at 00:43
  • This looks like a question which will mainly get opinion based answers. Is there a specific coding style you are trying to follow? – Trisped Jan 20 '22 at 00:43
  • 1
    `&&` is a binary operator. It’s impossible for the two lines to be two separate statements, no matter which line you put the `&&` on. Have you seen [What are the rules for JavaScript's automatic semicolon insertion (ASI)?](/q/2846283/4642212)? – Sebastian Simon Jan 20 '22 at 00:44
  • 1
    @Trisped nope I just want to make sure I don't get errors in terms of putting it over multiple lines. Style I'm not concerned about. – David542 Jan 20 '22 at 00:44
  • @SebastianSimon no `&&` is logical: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND. `&` is bitwise: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND – David542 Jan 20 '22 at 00:45
  • 3
    @David542 I mean the other meaning of binary: requiring two operands. As opposed to unary or ternary or any other _n_-ary for _n_ ≠ 2, or even variadic. – Sebastian Simon Jan 20 '22 at 00:46

0 Answers0