I think I have the bones of a solution to this exercise ( Record Collection) , but I’m getting tripped up on syntax. Can someone tell me what I am missing here:
function updateRecords(records, id, prop, value) {
if (prop != 'tracks' && value.hasOwnProperty = true) {
prop = value;
I get this error:
SyntaxError: unknown: Invalid left-hand side in assignment expression. (24:4)
22 | // Only change code below this line
23 | function updateRecords(records, id, prop, value) {
> 24 | if (prop != 'tracks' && value.hasOwnProperty = true) {
| ^
Am I using the operator incorrectly? Or is this some sort of dumb syntax thing I am just plain missing?
you want to use the equality operator here (===), not an assignment. And value.hasOwnProperty is not a correct piece of code.
And if some expression returns a boolean value, then comparing the returned value with boolean is redundant. if (obj.hasOwnProperty("somePropName")) // correct if (obj.hasOwnProperty("somePropName") === true) // correct, but redundant
.hasOwnProperty is to be applied on object type so to check whether the object records has a property has the value of variable prop or not it should be done like records.hasOwnProperty(prop)==true
but as you have to check for the prop inside objects nested in records object you’ll have to use bracket notation to access the id and then check for property.
My explanation might be weird bcz i learnt js recently and solved this question today only.