Why I get "Invalid left-hand side in assignment"?

There is code:

function search(list, q){
  var result = {};
  for(let id in list)(
    (!q.id    || (id == q.id)) &&
    (!q.name  || (list[id].name.search(q.name) > -1)) &&
    result[id] = list[id]
  );

  return result;
}

I get this error:

Uncaught ReferenceError: Invalid left-hand side in assignment    script.js:4

Why “&&” is wrong?

Source: AngularJS

Comment (1)

  • Max Payne| April 20, 2018

    Instead of

    result[id] = list[id]

    use

    result[id] == list[id]

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.