You'll need to expose some sort of API that your JavaScript can use to request data from your Craft install. 

There are two first-party options:

 1. Craft CMS has had [GraphQL][1] support built into core since version 3.3.0. [The official docs][2] provides a fairly comprehensive guide to get up and running.

 2. If you prefer a RESTful API, the first-party [Element API plugin][3] provides a simple interface to configure your endpoints. The documentation for Element API can be found [on the plugin's GitHub page](https://github.com/craftcms/element-api). The Element API plugin is available for both Craft 3 and 4.

Aside from the above, if you happen to use Gatsby for your site there's also a first-party [Gatsby source plugin][4] for Craft.

Finally, when using Craft as a CMS for a headless app/site, it's also worth knowing about the [`headlessMode`][5], which "optimizes the system and control panel for headless CMS implementations".


  [1]: https://graphql.org/
  [2]: https://craftcms.com/docs/3.x/graphql.html
  [3]: https://plugins.craftcms.com/element-api?craft3
  [4]: https://github.com/craftcms/gatsby-source-craft
  [5]: https://craftcms.com/docs/3.x/config/general.html#headlessmode