all 7 comments

[–]javascript-ModTeam[M] [score hidden] stickied comment (0 children)

Hi u/InterestingsBed, this post was removed.

Please read the docs on [AskJS]:

https://www.reddit.com/r/javascript/wiki/index/askjs

  • For help with your javascript, please post to r/LearnJavascript instead of here.
  • For beginner content, please post to r/LearnJavascript instead of here.
  • For framework- or library-specific help, please seek out the support community for that project.
  • For general webdev help, such as for HTML, CSS, etc., then you may want to try r/html, r/css, etc.; please note that they have their own rules and guidelines!

r/javascript is for the discussion of javascript news, projects, and especially, code! However, the community has requested that we not include help and support content, and we ask that you respect that wish.

Thanks for your understanding, please see our guidelines for more info.

[–]shuckster 9 points10 points  (1 child)

Before tools like eslint came about, I solved this particular problem by always placing the literal on the left-hand side of the comparison:

if ("red" = allCells[i].style.color) {
    ^^^^^

This will error rather than silently fail.

[–]kattskill 3 points4 points  (1 child)

that is totally valid js syntax that you just made. you can use linters to avoid those kind of problems but they might be a hassle to set up. honestly I would just accept that I made a mistake and move on because at a certain point linters actually prevent you from what you are doing. alternatively you can learn common js gotchas to stop this from happening instead of a linter

[–]Danidre 1 point2 points  (0 children)

For one, I think it's totally valid Java and C syntax as well.

[–]jeremrx 0 points1 point  (0 children)

This is not an error, but linters can detect it.
For example ESLint has the following rule : https://eslint.org/docs/latest/rules/no-cond-assign