@justjim1220 Same for me I am absolutely new to javascript. I generally know the system const because I use a lot of c++, but testing here seems like the variables actually get not deleted after SocketNotificationreceived function ends. And I have absolutely no clue on when to use the type let and which advantage it offers over var, because on some variables let works on others only var. const actually never worked in there.
I have my code here not fully ready yet:
socketNotificationReceived: function(notification, payload) {
if (notification === 'HIDE_SHOW') {
var obj = JSON.parse(payload.data.toString());
var max = obj.slots.length;
for (let i = 0; i < max; ++i){
if (obj.slots[i].slotName === "HIDE" ||
obj.slots[i].slotName === "SHOW") {
var HideShow = obj.slots[i].slotName;
}
}
for (let i = 0; i < max; ++i){
if (obj.slots[i].slotName === "MODULE") {
var Module = obj.slots[i].value.value;
break;
}
}
var Message = HideShow + "_" + Module;
const moduleToMove = 'clock';
const targetRegion = 'top.left';
MM.getModules().enumerate((module) => {
if (module.name === moduleToMove) {
const instance = document.getElementById(module.identifier);
const region = document.querySelector(`div.region.${targetRegion} div.container`);
region.appendChild(instance);
//region.insertBefore(instance, region.childNodes[0])
region.style.display = 'block';
}
});
this.loaded = true;
this.sendNotification(Message);
}
if (notification === 'ERROR') {
this.sendNotification('SHOW_ALERT', payload);
}
}
So at which positions would it be better to use const/let instead of var? And how is the performance of them? Because in c++ I definetly use const a lot for variables or member functions