Coding Walkthrough #4: Collision freezes the project?

Video Description:

To go in more detail about 3:11:
Uncaught TypeError: Cannot read property '0' of undefined at brickCollision...


This gives us a lot of detailed information with how we're going to solve this problem

  • The error is when the brickCollision() function is evaluated by the compiler
  • Compiler is try to read a property
  • Specifically,  the complier is trying to read the property '0'


There are 2 ways to access a property in JavaScript. I mentioned the dot '.' notation in the video. And the other way is using the '[' and ']' AKA square brackets. So the compiler is failing to evaluate two options:
  • someObject.0
  • someObject.someProp[0]
You can read more about property accessors in the Mozilla Developer Network Web Docs.

The second option occurs at line 238 (3:54) in the brickCollision() function. It then continues on until all the brickarray.xPos[0] or brickarray.yPos[0] is corrected.