![Simple minesweeper javascript - code](https://cdn2.cdnme.se/5447227/9-3/23_64e61dfde087c337bd195b74.jpg)
![simple minesweeper javascript - code simple minesweeper javascript - code](https://codeprojectz.com/wp-content/uploads/2021/08/Minesweeper-Game-In-C-With-Source-Code.jpg)
![simple minesweeper javascript - code simple minesweeper javascript - code](https://www.learningjs.co.uk/img/post-images/minesweeper-thumbnail.png)
If ( gameOver ) return // NOTE: logic check change. but no code after the block before returning from the function. If there is no code after the if statement and the end of the function - just swap the logic and return early. and how do you know when something can be flattened? this simple refactoring reduced the depth of the if statements from ~5 to 1.many of the other functions could be flattened just like this. I may have missed something, but hopefully you get the point. If ( cell.opened || cell.flagged ) return
![simple minesweeper javascript - code simple minesweeper javascript - code](https://i.pinimg.com/originals/7b/34/0c/7b340c1f8a722d5dbf04caa8d50f87d7.jpg)
So - your handleClick function could be rewritten (with stuff removed) as: meaning, if you find that you're nesting "ifs" more than a couple of levels deep, the code may be a candidate for flattening. It can be incredibly beneficial (for readability, catching logic errors, etc.) to "exit early" from "if" statements. Can i make a (hopefully useful) comment about programming style - something that someone shared with me a long time ago when reading my code that i have found to be very valuable over the years?
![Simple minesweeper javascript - code](https://cdn2.cdnme.se/5447227/9-3/23_64e61dfde087c337bd195b74.jpg)