Lots of Mac tools want a bundle identifier like com.apple.Safari instead of an app name: defaults, configuration profiles, open -b. AppleScript knows it for every app you have.
Ask with a one-liner. Mind the quotes: single quotes around the script, double quotes around the app name.
osascript -e 'id of app "Safari"'
The answer here is com.apple.Safari. It works for third-party apps too, as long as the name matches the app in your Applications folder, for example "Visual Studio Code" or "Firefox".
Once you have the ID you can feed it to other commands. A nice one: open an app by its ID, which keeps working even if someone renamed the app file.
open -b com.apple.Safari
Why AppleScript and not something else? I like it because it’s on every Mac, it needs no extra tools, and the result is clean enough to use in a variable: BID=$(osascript -e 'id of app "Notes"').
One thing to watch: if the name doesn’t match an installed app, macOS may pop up a dialog asking where the app is, and your script waits for it. Spell the name exactly as Finder shows it, without .app, and check a new name by hand before you put it in a script.
Further reading: osascript.1 man page, open.1 man page