0

I was going through a piece of js example code(im still learning) then i came across this part

(

  class Network {
    constructor(connections, storageFor) {
      let reachable = Object.create(null)
      for (let [from, to] of connections.map(conn => conn.split("-"))) {
        ;(reachable[from] || (reachable[from] = [])).push(to)
        ;(reachable[to] || (reachable[to] = [])).push(from)
      }
      this.nodes = Object.create(null)
      for (let name of Object.keys(reachable))
        this.nodes[name] = new Node(name, reachable[name], this, storageFor(name))
      this.types = Object.create(null)
    }

    defineRequestType(name, handler) {
      this.types[name] = handler
    }

    everywhere(f) {
      for (let node of Object.values(this.nodes)) f(node)
    }
  }
)()

I need clarity on this part

;(reachable[from] || (reachable[from] = [])).push(to)
;(reachable[to] || (reachable[to] = [])).push(from)

Why does the semicolon preceed the expression?

  • Basically, it's sometimes needed when the line starts with a parenthesis (and certain other special cases). – John Montgomery Mar 20 '20 at 22:16
  • ...if you don't end your lines with a semicolon. – jonrsharpe Mar 20 '20 at 22:17
  • 1
    lesson here is "always end statements with a semi-colon" so future people who have NOT memorized the https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Automatic_semicolon_insertion – Mark Schultheiss Mar 20 '20 at 22:22

0 Answers0