Hey all - I’m trying to understand what’s happening in the following code block and a question popped in my head that I couldn’t make sense of. Here’s the code:
if (requestArticle && requestArticle.title && requestArticle.url &&
requestArticle.username && database.users[requestArticle.username]) {
const article = {
id: database.nextArticleId++,
title: requestArticle.title,
url: requestArticle.url,
username: requestArticle.username,
commentIds: [],
upvotedBy: [],
downvotedBy: []
};
database.articles[article.id] = article;
database.users[article.username].articleIds.push(article.id);
It seems we’re defining the variable article
as an object with a set of properties. But then below that, it’s almost as if we’re redefining article (which doesn’t make sense due to const
syntax) as database.articles[article.id]
. What’s going on here? What is the difference between having code on one side of =
vs the other?
Thank you!