Skip to content

no error when comparing typeof to undefined or null #42090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DetachHead opened this issue Dec 23, 2020 · 1 comment
Closed

no error when comparing typeof to undefined or null #42090

DetachHead opened this issue Dec 23, 2020 · 1 comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@DetachHead
Copy link
Contributor

Bug Report

πŸ”Ž Search Terms

typeof undefined null

πŸ•— Version & Regression Information

v4.2.0-dev.20201223

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about typeof

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

//error: This condition will always return 'false' since the types
//'"string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"' and '"asdf"' have no overlap.
typeof undefined === 'asdf'

//no error, even though these conditions will also always be false:
typeof undefined === undefined
typeof undefined === null

πŸ™ Actual behavior

no error when comparing typeof undefined to null or undefined

πŸ™‚ Expected behavior

"This condition will always return 'false'" error, as there is no overlap with the return type of typeof (which is "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function")

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#Description

@MartinJohns
Copy link
Contributor

Duplicate of #29405 / #29200. Used search terms: typeof undefined null in:title

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants