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
}
}