Intellisense ist not supported for inline JavaScript in Visual Studio Code. There is an open issue for this since 2017: https://github.com/microsoft/vscode/issues/26338
And a PR, which would resolve it (from January 2023): https://github.com/microsoft/vscode/pull/171547
So this would be the reason, why the variable defined in your inline JavaScript is not found in another JavaScript file.