1. If you don’t declare the i variable locally, JavaScript will create a global one for you. You’ll probably get away with it, but you could get into trouble if you already have one declared globally and you start using it locally to control your for loop.
2. That’s just checking to see if the layer actually has any masks. My assumption was no masks = no keyframes, but you may want to handle that situation differently (just skip that layer maybe?)
3. If you don’t already have Jeff Almasol’s incredibly useful rd_GimmePropPath.jsx script you should get it. I use it all the time to examine complex property hierarchies and get the match names for properties.