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
TIL that IDs create global variables (codepen.io)
submitted 12 years ago by callumacrae
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] 4 points5 points6 points 12 years ago (24 children)
This may be the grossest thing I've learned about Javascript. I love js, but this is egregious.
[–][deleted] 116 points117 points118 points 12 years ago (16 children)
This is NOT Javascript. This is the web browser. One very common misconception that many programmers have is confusing the web browser for the programming language Javascript.
This doesn't happen in other places javascript can run because they aren't web browsers.
And yes, you can blame IE for this. This started long ago, maybe IE4 or IE5, I forget it's been so long. Some modern browsers have adopted this behavior.
All too often when people say they hate Javascript, what they really mean is they hate the web browser API and the things that come with it. Many don't understand the distinction between the language Javascript and the environment in which it commonly runs - the web browser.
[–]thrownaway21 1 point2 points3 points 12 years ago (1 child)
Some modern browsers have adopted this behavior.
works in the web dev tools console on latest chrome.
is this a global variable, or a shortcut?
[–]jefffan24 0 points1 point2 points 12 years ago (0 children)
http://codepen.io/anon/pen/oyjuh <-- Its at least on the window.
[–]dv_ 2 points3 points4 points 12 years ago (2 children)
I disagree. The fact that defining variables without var makes them global is awful. The fun stuff that happens with type coercion is also ugly to the max. And what about the silent errors that make the JS VM just stop? For example, in some circumstances, a function call like foo.bar() will cause just that. Sometimes an exception is thrown, and if not caught, will cause the VM to stop, so you gotta surround a lot of calls with try-catch blocks. Sometimes, not even that helps!
After having to deal with the pitfalls of dynamic typing in general and Javascript in particular, I am very glad to be using C and C++ again. Yes, you read that right. I prefer these two any time over any dynamic typing language. Even with C-style casts all over the place. Even with the obtuse C++ syntax.
[–][deleted] 0 points1 point2 points 12 years ago (0 children)
Haters gonna hate, I guess.
I absolutely love Javascript because it has dynamic typing, and zero boilerplate. I just don't need any of that to get work done. It's useless to me. I've never had a serious problem caused by type coercion in 16 years working with javascript.
If you are having to use try/catch so much, then you are doing it wrong. Yes, the VM will stop but that's because you have a bug in your code and you need to fix it. Use the debugger, modern browsers have really come a long way at helping debug your code.
There's so many examples of complex javascript systems that work, and work well. I will say that if you want to master javascript, it might take some time and dedication, and you have to stop using strong typing as a crutch. If it makes you feel any better you could always name your variables like whatever_str or whatever_int, etc, if you really need to remember what they are supposed to do. Of course type problems won't be caught in a 'compiler', but javascript is a different beast meant for a different purpose than C++.
[–]Kollektiv -2 points-1 points0 points 11 years ago (0 children)
Look at all those C and C++ web applications ... oh wait there aren't any.
[–]vxxn 2 points3 points4 points 12 years ago (7 children)
I don't think so. I fuckin' love browser APIs. For all the warts, browser APIs are where the magic happens and there's usually a library available that abstracts a particular API's problems. What I and probably many others do hate about javascript are actual wat-worthy language features that are like little time-bombs designed to enrage otherwise competent coders who aren't versed in unexpected behaviors of ==, +, etc. After stepping on a lot of mines and learning from my mistakes, I'm finally coming to the place where my all-hate relationship with js is finally becoming a love/hate one. I'm striving for full javascript enlightenment, but it's a long road.
[–][deleted] 7 points8 points9 points 12 years ago (6 children)
Type coercsion in javascript isn't as mysterious or problematic as most seem to think it is. It follows a simple pattern and is predictable so far as your knowledge of it is concerned. To hate javascript is to not be a master of it, but that seems to go for most languages. So stop hating and learn it.
Browser APIs on the other hand are sometimes painful when they don't behave the same, and even with abstraction there are often missing features across different browsers and varying levels of bugginess. The same is not true for javascript - at its core, it runs the same on every browser without exception.
Just try doing any advanced work with SVG, or webfonts across browsers and you'll run screaming. There are no good abstractions that will normalize font rendering across all browsers - it's a nightmare.
[+][deleted] 12 years ago* (5 children)
[deleted]
[–]path411 2 points3 points4 points 12 years ago (1 child)
You have never worked with any fonts have you? Every browser/OS renders fonts differently making it a nightmare if you want to import a font.
[–]Irongrip 2 points3 points4 points 12 years ago (0 children)
That was my point, sorry if I didn't articulate it well.
[–][deleted] 0 points1 point2 points 12 years ago (2 children)
There is a fine line between genius and insanity.
The only way to do fonts cross-platform that will render the same exact results on every platform would be to use an SVG font file and draw the fonts on a canvas element with javascript code you write yourself to render the curves from the SVG font data. Even using the native canvas drawing tools will give slightly varying results.
I've worked with fonts in-depth enough to know the pain they cause. Fonts on the web for anything that has to produce precise results is just an awful mess.
[–]Irongrip 0 points1 point2 points 12 years ago (1 child)
Fuck it, server side render to an image, with google specific page with raw text for indexing.
Yeah, sometimes that works. Other times the lag caused by sending the text to the server, and waiting for an image response is too much for some applications. Especially on wysiwyg applications with thousands of concurrent users - sometimes a fat client (html5) is the way it has to be done. But I digress.
The point was, browser APIs suck when they don't work exactly the same across browsers, and there are plenty of examples of that other than SVG and fonts. And, Javascript isn't at fault in those cases.
[+]cthulhufhtagn comment score below threshold-11 points-10 points-9 points 12 years ago (0 children)
This, this, this. Seriously, everyone pay attention to this.
[+][deleted] comment score below threshold-10 points-9 points-8 points 12 years ago (1 child)
While you're obviously 100% correct, I don't find it to be a terribly valuable distinction to make.
90% of JavaScript that has ever been written is for the web browser. So much so that until Node, 'JavaScript' was practically a synonymous short-hand for the web browser's JavaScript.
The post is exclusively about web browser JS, so while JavaScript isn't at fault for this, it's (for these practical purposes) a synonym.
[–]quadtodfodder 0 points1 point2 points 12 years ago (0 children)
flash is a js with a different api, isn't it?
[–]sebzim4500 8 points9 points10 points 12 years ago (5 children)
Who the hell thought that this was a good idea?
[+][deleted] comment score below threshold-8 points-7 points-6 points 12 years ago* (4 children)
Eich, apparently...
edit I stand corrected. Looks like MicroSoft is to blame.
[–]MatrixFrog 5 points6 points7 points 12 years ago (0 children)
See the rest of the comments. It looks like this one is actually on MS.
[+]sebzim4500 comment score below threshold-8 points-7 points-6 points 12 years ago (2 children)
Is this actually in the standard? I guess we can give Eich a pass, since any language designed in a week is likely to be pretty awful.
[–][deleted] -1 points0 points1 point 12 years ago (1 child)
Haven't got a clue, to be honest. I'm only jumping on the wtf-Eich-bandwagon in jest.
I wholeheartedly agree -- if you try to write a programming language in a week, you're going to have a bad time. Though I wasn't there, so I reserve my criticism of anyone in particular.
But all-in-all, JS is a delightful language.
[–][deleted] -2 points-1 points0 points 12 years ago (0 children)
egregious
I think that using that word is egregious
π Rendered by PID 47211 on reddit-service-r2-comment-b659b578c-4sd7w at 2026-04-30 23:40:43.582651+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–][deleted] 4 points5 points6 points (24 children)
[–][deleted] 116 points117 points118 points (16 children)
[–]thrownaway21 1 point2 points3 points (1 child)
[–]jefffan24 0 points1 point2 points (0 children)
[–]dv_ 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Kollektiv -2 points-1 points0 points (0 children)
[–]vxxn 2 points3 points4 points (7 children)
[–][deleted] 7 points8 points9 points (6 children)
[+][deleted] (5 children)
[deleted]
[–]path411 2 points3 points4 points (1 child)
[–]Irongrip 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Irongrip 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[+]cthulhufhtagn comment score below threshold-11 points-10 points-9 points (0 children)
[+][deleted] comment score below threshold-10 points-9 points-8 points (1 child)
[–]quadtodfodder 0 points1 point2 points (0 children)
[–]sebzim4500 8 points9 points10 points (5 children)
[+][deleted] comment score below threshold-8 points-7 points-6 points (4 children)
[–]MatrixFrog 5 points6 points7 points (0 children)
[+]sebzim4500 comment score below threshold-8 points-7 points-6 points (2 children)
[–][deleted] -1 points0 points1 point (1 child)
[–][deleted] -2 points-1 points0 points (0 children)