'token' is never reassigned. Use 'const' instead
56 id: userId,
57 },
58 }
59 let token = jwt.sign({ payload }, secretKey, { 60 expiresIn: expiresIn,
61 });
62 return responseMsg(200, 'OK', 'User created successfully', token)
'token' is never reassigned. Use 'const' instead
105 id: user.userid,
106 },
107 }
108 let token = jwt.sign({ payload }, secretKey, {109 expiresIn: expiresIn,
110 });
111 return responseMsg(200, 'OK', 'User logged in successfully', token)
Description
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.
Bad Practice
let pi = Math.PI
for (let x of xs) {
use(x);
}
let { a, b } = object;
use(a, b);
Recommended
const pi = Math.PI
for (const x of xs) {
use(x);
}
const { a, b } = object;
use(a, b);