Course contentsShow
← JavaScript
Lesson 2572 of 2,72352. Linting and FormattingFree lesson

Flat Config: Language Options and Globals

Configure language features, parser options, and global variables in the flat config format.

Flat Config: Language Options and Globals

You'll learn how to configure JavaScript language features, parser settings, and global variables within ESLint's modern flat config format.

What Are Language Options?

In flat config (eslint.config.js), the languageOptions key is where you specify how ESLint should interpret your JavaScript code. Think of it as setting the "rules of the language" — which ECMAScript version you're using, what kind of module system, and what global variables exist in your environment.

This replaces the scattered parserOptions, env, and globals fields from legacy .eslintrc configs, consolidating them into one clear object.

Structure of languageOptions

export default [
  {
    languageOptions: {
      ecmaVersion: 2024,           // or "latest"
      sourceType: "module",         // "script" or "module"
      parserOptions: {
        ecmaFeatures: {
          jsx: true                 // Enable JSX syntax
        }
      },
      globals: {
        myGlobalVar: "readonly",    // Define custom globals
        API_KEY: "writable"
      }
    }
  }
];

ecmaVersion tells ESLint which JavaScript features to expect (like async/await, optional chaining, etc.).

sourceType distinguishes between ES modules (import/export) and classic scripts.

globals explicitly declares variables that exist but aren't defined in your files (like browser APIs or build-time injected constants). Mark them "readonly" or "writable" to prevent accidental overwrites.

Why This Matters

Without declaring globals, ESLint will flag legitimate variables as undefined. With wrong parser settings, it may reject valid modern syntax. Language options ensure ESLint speaks the same JavaScript dialect as your project.

Key Takeaway: The languageOptions object in flat config centralizes how ESLint interprets your code's syntax and environment, replacing fragmented legacy settings with a single, clear configuration point.