Environment Configuration
What you'll learn: How to tell ESLint which JavaScript environments your code runs in so it doesn't incorrectly flag legitimate global variables as errors.
The Problem ESLint Solves
When you write JavaScript, different runtime environments provide different global variables. In a browser, you have window, document, and fetch. In Node.js, you have process, __dirname, and require. If ESLint doesn't know where your code runs, it will flag these perfectly valid globals as undefined variables—filling your screen with false positives.
Declaring Your Environment
The env field in your .eslintrc configuration tells ESLint which global variables should be recognized automatically. Think of it like declaring which "rulebooks" apply to your code:
{
"env": {
"browser": true,
"node": true,
"es6": true
}
}
browser: Enables globals like window, document, alert, localStorage
node: Enables globals like process, Buffer, __dirname, global
es6: Enables ES6 syntax features and globals like Promise, Map, Set
You can enable multiple environments simultaneously if your code runs in mixed contexts (like a full-stack project with both client and server code).
Why This Matters
Without proper environment configuration, ESLint would complain that document.getElementById('app') uses an undefined variable. With "browser": true, ESLint knows document is a legitimate global and focuses on actual problems in your code.
Key Takeaway: Use the env field in your ESLint config to specify where your code runs (browser, Node.js, ES6, etc.), preventing false warnings about environment-specific globals.