Skip to content

Instantly share code, notes, and snippets.

@patarapolw
Last active August 23, 2019 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patarapolw/59303874438a521370859d507c0429b6 to your computer and use it in GitHub Desktop.
Save patarapolw/59303874438a521370859d507c0429b6 to your computer and use it in GitHub Desktop.
JavaScript instance type checking.
function isSameType(a, b) {
const tA = typeof a;
const tB = typeof b;
if (tA !== "object") {
return tA === typeof b;
} else if (tB === "object") {
return a.constructor === b.constructor;
}
return tA === tB; // always false???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment