typeof
expressions should be compared against valid strings JS-0028323
324 // Self is not defined within Node environments
325 // This check is needed because the user agent cannot be set in a browser
326 if (typeof self === undefined) {327 opts.headers = {
328 "User-Agent": `dhive/${packageVersion}`,
329 };
86 },
87
88 is_digits: (is_digits = function (value) {
89 if (typeof value === 'numeric') { 90 return true
91 }
92 return /^[0-9]+$/.test(value)
It is usually a typing mistake to compare the result of a typeof
operator to string literals other than the expected results like undefined
, string
, boolean
, object
etc.
typeof foo === "strnig"
typeof foo == "undefimed"
typeof bar != "nunber"
typeof bar !== "function"
typeof foo === "string"
typeof bar == "undefined"
typeof foo === baz
typeof bar === typeof qux