Question: JavaSript Fundamentals

I decided to buy off Mosh’s highly rated JavaScript course and I have some questions. I can’t say I’m completely new to JS since I already posted ReactJS questions here before but some exercises from his course did lead me to such questions.

In one of Mosh’s exercises, regarding object equality. I’d like to know, is this the only way to compare objects?

function areEqual(address1, address2) {
  return (
    address1.street === address2.street &&
    address1.city === address2.city &&
    address1.zipCode === address2.zipCode
  )
}

Based on my research json.stringify exists, but that alone doesn’t even represent all data types.

Edit: I would also like to ask,
Should we really use Constructor functions?

function Post(title, body, author) {
  this.title = title
  this.body = body
  this.author = author
  this.views = 0
  this.comments = []
  this.isLive = false
}

Over class based approach?

class Post {
  constructor(title, body, author) {
    this.title = title
    this.body = body
    this.author = author
    this.views = 0
    this.comments = []
    this.isLive = false
  }
}

Hi siyeon,

There are other ways to compare objects, for example you could use the isEqual() function from lodash library here

For the constructor question, I think in modern js its more conventional to use the class based approach as we get to leverage features of object oriented programming such as inheritance, for older more legacy codebases then function based approach makes sense

Sorry for the late reply, and as I thought so. That said, how old exactly is Mosh’s JavaScript course? I ended up asking this question because of the examples I’m seeing on his JavaScript lessons.