|
| 1 | +# E057: use of undeclared variable |
| 2 | + |
| 3 | +```config-for-examples |
| 4 | +{ |
| 5 | + "globals": { |
| 6 | + "isHappy": true |
| 7 | + } |
| 8 | +} |
| 9 | +``` |
| 10 | + |
| 11 | +It is an error to use a function or variable without declaring it: |
| 12 | + |
| 13 | + consol.write("Hello, world!"); |
| 14 | + const one = Math.sin(pi/2); |
| 15 | + |
| 16 | + function encrypt() { |
| 17 | + return data ^ 0x13371337; |
| 18 | + } |
| 19 | + |
| 20 | + if (isHappy) { |
| 21 | + let emotion = "happy"; |
| 22 | + } else { |
| 23 | + let emotion = "sad"; |
| 24 | + } |
| 25 | + console.log("I am " + emotion); |
| 26 | + |
| 27 | + function MyComponent({}) { |
| 28 | + let [pressed, setPressed] = useState(false); |
| 29 | + } |
| 30 | + |
| 31 | + google.charts.load('current', {'packages':['corechart']}); |
| 32 | + |
| 33 | +To fix this error, fix the name of the function or variable: |
| 34 | + |
| 35 | + console.write("Hello, world!"); |
| 36 | + const one = Math.sin(Math.pi/2); |
| 37 | + |
| 38 | +Alternatively, declare the function or variable: |
| 39 | + |
| 40 | + function encrypt(data) { |
| 41 | + return data ^ 0x13371337; |
| 42 | + } |
| 43 | + |
| 44 | +Alternatively, move the declaration of the variable into an outer scope: |
| 45 | + |
| 46 | + let emotion; |
| 47 | + if (isHappy) { |
| 48 | + emotion = "happy"; |
| 49 | + } else { |
| 50 | + emotion = "sad"; |
| 51 | + } |
| 52 | + console.log("I am " + emotion); |
| 53 | + |
| 54 | +Alternatively, import the function or variable: |
| 55 | + |
| 56 | + import { useState } from "react"; |
| 57 | + function MyComponent({}) { |
| 58 | + let [pressed, setPressed] = useState(false); |
| 59 | + } |
| 60 | + |
| 61 | +Alternatively, if the function or variable is global in your environment, [write |
| 62 | +a quick-lint-js.config file](https://quick-lint-js.com/config/). |
0 commit comments