const
declarations for variables that are never reassigned JS-0242 51 };
52 const handleProductImage = (e: ChangeEvent<HTMLInputElement>) => {
53 if (e.target.files) {
54 let preview = URL.createObjectURL(e.target.files[0]); 55 const newProductData = {
56 ...product,
57 images: [e.target.files[0]],
51 };
52 const handleNewPfp = (e: ChangeEvent<HTMLInputElement>) => {
53 if (fileRef.current.files) {
54 let preview = URL.createObjectURL(fileRef.current.files[0]); 55 setPfp(fileRef.current.files[0]);
56 const newUserData = { ...userInfo, pfp: preview } as User;
57 setUserInfo(newUserData);
Variables that are never re-assigned a new value after their initial declaration should be declared with the const
keyword.
This prevents the programmer from erroneously re-assigning to a read-only variable, and informs those reading the code that a variable is a constant value.
let pi = Math.PI
for (let x of xs) {
use(x);
}
let { a, b } = object;
use(a, b);
const pi = Math.PI
for (const x of xs) {
use(x);
}
const { a, b } = object;
use(a, b);