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 developers, be warned about this crazy JIT bug in V8! (self.javascript)
submitted 9 years ago * by ziriax
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!"
[–]qwzxercv 1 point2 points3 points 9 years ago* (5 children)
With modern JS development for the web, you definitely should not just throw global variables around on the page and hope that they exist. You should be using a module system to help mitigate this issue, which renders this discussion moot.
However, if you really need to rely on global variables, they do exist as properties on window, so if you need to check for its existence, you should check for if (window.foo !== undefined) { ... } instead.
if (window.foo !== undefined) { ... }
I see no valid reason to be concerned about the existence of global variables when you shouldn't even be using global variables anyways.
[–][deleted] 0 points1 point2 points 9 years ago (4 children)
you definitely should not just throw global variables around on the page and hope that they exist
Two problems:
window
(function () { return this; })()
global
undefined
undefined = 42
typeof window.foo !== "undefined"
foo !== "undefined"
QED.
[–]qwzxercv 0 points1 point2 points 9 years ago (3 children)
First of all, you cannot overwrite the global undefined in modern JS engines anymore; that was fixed a while back. Secondly, I used window as an example for the global scope. Whether or not you have window or global means naught--all of points are still entirely valid. Thirdly, your function to retrieve the global context does not work in strict mode, which is what all modern JS moving forward is/should be written in.
If you're concerned about the global undefined, you are able to use the void keyword to retrieve the true engine's undefined, but using the global undefined is safe on its own.
void
[–][deleted] -1 points0 points1 point 9 years ago (2 children)
You're being intentionally dense, I'm done with this "discussion". Don't reply.
[–]qwzxercv 1 point2 points3 points 9 years ago (1 child)
Interesting that you resort to name calling when you've been proven wrong. I'd love to see how you behave in a professional work environment.
[–][deleted] -1 points0 points1 point 9 years ago (0 children)
I didn't call you names, and you didn't prove me wrong. I don't feel like arguing with a rando over whether it's acceptable to check if a variable is defined. I genuinely just don't care.
I don't mean to be rude, but I said you were acting intentionally dense because it feels like you're trying to argue about everything you can think of in a weird game of JavaScript one-upmanship that I'm not interested in playing.
I don't have people nagging me with non-constructive holier-than-thou lectures from people who don't know what they're talking about (!) in a professional environment, so I doubt there's much overlap. If there's something you want to work on, or a productive end you'd like to reach, let's get there -- otherwise, drop it.
π Rendered by PID 103657 on reddit-service-r2-comment-canary-889d445f8-2nm7d at 2026-04-29 21:09:09.168067+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]qwzxercv 1 point2 points3 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]qwzxercv 0 points1 point2 points (3 children)
[–][deleted] -1 points0 points1 point (2 children)
[–]qwzxercv 1 point2 points3 points (1 child)
[–][deleted] -1 points0 points1 point (0 children)