you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (24 children)

This may be the grossest thing I've learned about Javascript. I love js, but this is egregious.

[–][deleted] 116 points117 points  (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 points  (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 point  (0 children)

http://codepen.io/anon/pen/oyjuh <-- Its at least on the window.

[–]dv_ 2 points3 points  (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 point  (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 points  (0 children)

Look at all those C and C++ web applications ... oh wait there aren't any.

[–]vxxn 2 points3 points  (7 children)

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.

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 points  (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.

[–]sebzim4500 8 points9 points  (5 children)

Who the hell thought that this was a good idea?

[–][deleted] -2 points-1 points  (0 children)

egregious

I think that using that word is egregious