const
declarations for variables that are never reassigned JS-0242 36 }
37 }
38 let docRef
39 docRef = this.uid ? collectionRef.doc(this.uid) : collectionRef.doc() 40 console.log(data)
41 await docRef.set(data)
42 const docID = await getDocumentIdByContent(collectionRef, data)
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);