# no-optional-chaining-on-undeclared-variable πŸ“ Disallow optional chaining on undeclared variables. πŸ’ΌπŸš« This rule is enabled in the βœ… `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). This rule is _disabled_ in the β˜‘οΈ `unopinionated` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). Optional chaining only short-circuits when the checked value is `null` or `undefined`. It does not suppress a `ReferenceError` from reading an undeclared runtime variable at the base of an optional member or call operation. This rule focuses on optional operations rooted in an undeclared identifier or member chain, like `foo?.bar` and `foo.bar?.baz`. Broader undeclared-reference checks are covered by ESLint's [`no-undef`](https://eslint.org/docs/latest/rules/no-undef) rule. Declare the variable, configure it as a global, or access it through `globalThis` when the property may be absent. ## Examples ```js // ❌ iDontExist?.meNeither; // βœ… globalThis.iDontExist?.meNeither; ``` ```js // ❌ iDontExist?.(); // βœ… let iDontExist; iDontExist?.(); ``` ```js // ❌ iDontExist.meNeither?.(); // βœ… globalThis.iDontExist?.meNeither?.(); ```