I want to check if a property exists in my object or not, If it exists I want to add a number to it and if it doesn't I want to create a property and set the value to 1. I did everything and i used optional chaining and logical assignment but there is an error it says: Uncaught SyntaxError: Invalid left-hand side expression in postfix operation can you say whats the problem? here is the code:
const scores = {};
for (const player of Object.values(game.scored)) {
scores?.[player]++ && scores[player] = 1;
}
note: game.scored contains 4 names;
i did my best, i could do it with ternary operator and it worked but i want to know why it doesn't work with optional chaining and logical assignment