Skip to content

Conversation

@MaryRichelle
Copy link
Contributor

The typeof operator returns "undefined" when used with an undeclared variable,
console.log(typeof z) // "undefined".

However, directly accessing an undeclared variable (e.g., console.log(z)) throws a ReferenceError. This distinction is important for understanding JavaScript's behavior with undeclared variables and typeof.

Reference Mdn

MaryRichelle and others added 2 commits January 6, 2025 19:21
The `typeof` operator returns `"undefined"` when used with an undeclared variable,  `console.log(typeof z) // "undefined"`. 

However, directly accessing an undeclared variable (e.g., `console.log(z)`) throws a `ReferenceError`. This distinction is important for understanding JavaScript's behavior with undeclared variables and typeof.

Reference [Mdn](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof?#interaction_with_undeclared_and_uninitialized_variables)
@yangshun yangshun changed the title Fix: Type of undeclared ReferenceError --> undefined contents: fix behavior for typeof for undeclared variables Jan 8, 2025
Copy link
Member

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, thanks so much @MaryRichelle

@yangshun yangshun merged commit 0716a08 into greatfrontend:main Jan 8, 2025
@MaryRichelle MaryRichelle deleted the patch-2 branch January 8, 2025 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants