23 if(!canNotify())
24 return;
25
26 Notification.requestPermission().then(granted => {27 if(granted !== "granted")
28 return Promise.reject("denied");
29 }).catch(err => {
227 );
228}
229
230function getAction(id: string) {231 for(const action of staffActions) {
232 if(action.id === id) {
233 return action;
204 const checks = $("input[type=checkbox]");
205 if(checks.length === 0) {
206 alertLightbox("No posts selected");
207 return false;208 }
209 let postID = 0;
210 for(let i = 0; i < checks.length; i++) {
236 });
237 if(!getBooleanStorageVal("persistentqr", false))
238 closeQR();
239 return false;240 },
241 error: (_jqXHR, _status, error) => {
242 alertLightbox(error, "Error");
100 }
101
102 if(!getBooleanStorageVal("useqr", true)) {
103 return closeQR();104 }
105
106 const onPostingPage = $("form input[name=boardid]").length > 0;
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;
}