const
declarations for variables that are never reassigned JS-024217
18
19function main() {
20 let p = [];21 generatePrimes(p, 1e6);
22 return p[10000];
23};
1function generatePrimes(primes, MAX_SIZE){
2 let IsPrime = Array(MAX_SIZE).fill(true); 3
4 let p,i;
5 for (p = 2; p * p < MAX_SIZE;p++) {
2 let nray = Array.from(
3 String(n), (i) => (Number(i))
4 );
5 let reversed = nray.reverse(); 6
7
8 return String(n) === reversed.join("");
9};
10
11function main() {
12 let n = [];13 for (let i = 100; i < 1000; i++ ) {
14 for (let j = 100; j < 1000; j++) {
15 let k = i * j;
12 let n = [];
13 for (let i = 100; i < 1000; i++ ) {
14 for (let j = 100; j < 1000; j++) {
15 let k = i * j;16 if (isPalendromic(k)) {
17 n.push(k);
18 };
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);