Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion Topic: Var vs Const vs Let - Within Functions #6

Open
alishalabi opened this issue Jan 23, 2019 · 0 comments
Open

Discussion Topic: Var vs Const vs Let - Within Functions #6

alishalabi opened this issue Jan 23, 2019 · 0 comments

Comments

@alishalabi
Copy link

alishalabi commented Jan 23, 2019

(https://developer.mozilla.org/en-US/docs/Games/Tutorials/2D_Breakout_game_pure_JavaScript)

Context:
Throughout the course of this tutorial, I found converting all of the var variables with const or let variables (based on Airbnb's styleguide) was a great mental exercise . While many of these conversions were initially obvious (ex: Lives should almost always be let), many were not (ex: Should brickRowCount be let or const?).
Inevitably, for the less obvious variables - I found the best way to make a determination is to mentally go through your features and mentally identify which will change - shift those variable from (the default) const' to let`.

Discussion Point 1:
While the above method is thorough, it can take extra time. Are there any shortcuts used in industry to make a determination?

Discussion Point 2 :
How does this concept change when we are going through for loops?

Ex:

// Collision Detection (Brick)
    function collisionDetection() {
      for(var c=0; c<brickColumnCount; c++) {
        for(var r=0; r<brickRowCount; r++) {
          let b = bricks[c][r]
          if(b.status == 1) {
            if(x > b.x && x < b.x+brickWidth && y > b.y && y < b.y+brickHeight) {
              dy = -dy;
              b.status = 0;
              score++;
              if(score == brickRowCount*brickColumnCount) {
                alert("YOU WIN, YOU ROCK!")
                document.location.reload()
                clearInterval(interval)
              }
            }
          }
        }
      }
    }
soggybag pushed a commit that referenced this issue Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant