In short, the JavaScript option works in tandem with the HubSpot tracking code, where it can identify user only when they convert (i.e. form submission) or if it’s a returning user with an existing cookie.
If the user never converts, the custom event should still get recorded but won’t be associated to any contacts and will likely be shown as “Unknown User” in the custom event analytics.