67
68 logger.info(`[find_3_streamer] loaded total ${streamerIcons.length} icons and statistics`, streamerIconStats);
69
70 return [streamerIcons, streamerIconStats];71 }
72 catch(err)
73 {
54 fail = true;
55 error = `${watchingStreamer} is not in our whitelist`;
56 logger.info(error);
57 return [fail, error];58 }
59 if(!tagCommandEnabledStreamers.includes(watchingStreamer))
60 {
23 streamers = Object.keys(iconStats);
24 logger.debug("[init_4_storage] localStorage", iconMetadata, iconStats);
25 logger.debug("[init_4_storage] syncStorage", iconRenderOptions);
26 return streamers;27 }
28 catch(err)
29 {
372 try
373 {
374 logger.debug("[init_3_functions]");
375 return resetVariables();376 }
377 catch(err)
378 {
61 * @returns
62 */
63const waitForElement = (selector, parent, timeout=0) => {
64 return new Promise((resolve) => { 65 const parentElement = parent ?? document.body;
66 if (parentElement.querySelector(selector)) {
67 return resolve(parentElement.querySelector(selector));
Any code paths that do not have explicit returns will return undefined
.
It is recommended to replace any implicit dead-ends that return undefined
with a return null
statement.
As a convention, undefined
signals that an unexpected value has been produced as the
result of a logical error in the program.
A null
return, on the other hand, signals that the input to a function was incorrect,
or a value was 'not found'.
Having this distinction in code helps you figure out if something was caused because of a logical error, or malformed input to a function call.
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// whoops! Implicit undefined return
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
return; // Implicit undefined return.
}
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// `null` indicates there is no such user.
return null;
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
// `null` indicates there is no such file.
return null;
}