Variables declared outside functions have global scope:
const API_URL = "https://api.example.com"
function fetchData() {
console.log(API_URL) // Accessible here
}
function sendData() {
console.log(API_URL) // Accessible here too
}
Global variables are accessible from anywhere. Limit them to constants and configuration. Too many globals make code hard to reason about.