Re:Airbnb JavaScript Style Guide
by svieira on Thursday July 02, 2015 @11:02PM
(#9823181)
The fact that `typeof` is no longer safe [1][2] is news to me - it feels like they put in air bags and removed the seat belts.
[ Parent
| on HN ]
The only code affected by this would be code that uses typeof to check for the existence of a variable the same code defines later, which sounds like dumb code to begin with. I don't think there's any valid uses of typeof on possibly undefined variables besides checking for browser built-ins.
Using typeof(foo) === "undefined" is actually something that comes from back when it was pretty common to pollute the global namespace. There were actual javascript plugins/libraries/snippets that defined undefined and thus broke code that compared to it.
It's not an issue since using a non-hoisted variable before it was declared is an error.
Your editor should immediately highlight this error with a squiggly line.
That's... interesting. I guess it makes a little sense -- `let` seems to be for developers who don't like `var` semantics. Usually that seems to be about wanting block instead of function scope, but maybe there's a contingent that dislikes `undefined` too.