js: Clean up typeof … === "undefined" checks.

The only reason to use typeof foo === "undefined" is when foo is a
global identifier that might not have been declared at all, so it
might raise a ReferenceError if evaluated.  For a variable declared
with const or let or import, a function argument, or a complex
expression, simply foo === undefined is equivalent.

Some of these conditions have become impossible and can be removed
entirely, and some can be replaced more idiomatically with default
parameters (note that JavaScript does not share the Python misfeature
of evaluating the default parameter at function declaration time).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-03-24 12:14:12 -07:00
committed by Tim Abbott
parent 9840803c00
commit 6de39ae92d
10 changed files with 17 additions and 25 deletions

View File

@@ -679,7 +679,7 @@ export function maybe_get_stream_name(stream_id) {
export function is_user_subscribed(stream_id, user_id) {
const sub = get_sub_by_id(stream_id);
if (typeof sub === "undefined" || !sub.can_access_subscribers) {
if (sub === undefined || !sub.can_access_subscribers) {
// If we don't know about the stream, or we ourselves cannot access subscriber list,
// so we return undefined (treated as falsy if not explicitly handled).
blueslip.warn(
@@ -687,7 +687,7 @@ export function is_user_subscribed(stream_id, user_id) {
);
return undefined;
}
if (typeof user_id === "undefined") {
if (user_id === undefined) {
blueslip.warn("Undefined user_id passed to function is_user_subscribed");
return undefined;
}