const
declarations for variables that are never reassigned JS-0242 31 sockets[socket.id] = socket;
32
33 socket.emit('signupsuccessful',"Ok");
34 let allUsers = await userController.get_all_users(data.name); 35 socket.emit('allusers',allUsers);
36 }
37 catch(error){
16const userController = require('./api/controller/users');
17const messageController = require('./api/controller/messages');
18
19let sockets = {}; 20
21io.on("connection",(socket)=>{
22 console.log("New user joins");
23
24socket.on('signup',async (data)=>{
25 try{
26 let result = await userController.signup_user(data.name,data.password,socket.id); 27 if(result=="Name is taken"){
28 socket.emit('nameerr',result);
29 return;
163async function getARoom (sendby,sendto) {
164 try{
165 let room = sendby+sendto+"Room";
166 let result = await userController.add_rooms(sendby,sendto,room);167 return room;
168 }
169 catch(error){
162
163async function getARoom (sendby,sendto) {
164 try{
165 let room = sendby+sendto+"Room";166 let result = await userController.add_rooms(sendby,sendto,room);
167 return room;
168 }
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);