Disclaimer: I speak in absolutes below for brevity. Yes, nearly every “rule” in programming has exceptions.
Here’s my take.
1. JS Belongs in a .js File
2. JS Code Should be Static
StackOverflow uses this pattern. As does Google. So you’re in good company. Just view their source: