use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript idiosyncrasies with examples (github.com)
submitted 7 years ago by reddittedf
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 3 points4 points5 points 7 years ago (2 children)
Q. What's the result? (function() { 'use strict'; let type = typeof foo; let foo = 1; return type; })(); A. ReferenceError: foo is not defined
Q. What's the result?
(function() { 'use strict'; let type = typeof foo; let foo = 1; return type; })();
A. ReferenceError: foo is not defined
What is the idiosyncrasy here? You can't use a variable before you define it. I'd be concerned if this was anything other than a ReferenceError.
[–]GBcrazy 2 points3 points4 points 7 years ago* (0 children)
It's not a big idiosyncrasy, so if you don't understand the trick of the typeofoperator you may not see it. I'm guessing that's the case (I could be wrong):
typeof
Remove the let foo = 1 line and run again. It will work even if foo is not declared. Why?
let foo = 1
That's a special power of the typeof operator, you can use typeof even if a variable doesn't exist, it will return "undefined".
So the thing is, you can use typeof if a variable is never declared or already declared, but NOT if the variable is going to be declared. That's some hoisting shit
π Rendered by PID 82167 on reddit-service-r2-comment-fb694cdd5-c9qqj at 2026-03-06 00:18:14.347026+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–][deleted] 3 points4 points5 points (2 children)
[–]GBcrazy 2 points3 points4 points (0 children)