mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
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:
committed by
Tim Abbott
parent
9840803c00
commit
6de39ae92d
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user