Javascript has come into the spotlight and will probably be the number one used programming language soon. But javascript has a dark side in being one of the most difficult of languages to learn. Even Weird Al Yankovic knows that learning javascript is about as easy as learning the Klingon language. Here are 10 things to remember while on your journey.
Trying to explain to a newcomer to javascript why javascript is one, a real language, Two, ecma approved and three, different in different web browsers is a lost cause. After all if javascript is a language like PHP and built into the web browser it should be exactly the same everywhere. Shouldn't it?
Javascript is a very widely used scripting language but not all javascript is the same. In fact the ECMA (European Computer Manufacturers Association) script standard on which Javascript is based is in even wider use. Some ECMA script based APIs include CFScript (Cold Fusion), Actionscript (Flash) and JScript (Microsoft).
Javascript got off to the same bad start as HTML and CSS. It has gotten the reputation of not being universally compatible with all browsers having slightly different interpretations of it. Javascript has found itself as being another casualty of the browser wars.
When the javascript code and documentation was on Netscape.com it was hard to find and difficult to navigate. It is pretty much the same nowadays. Mozilla.org has control of javascript project but has not done much to improve the way it is presented. When new versions of javascript come out it is probably one of the webs best kept secrets. You can tell this by the fact that the javascript page has only been accessed a little under 24,000 times instead of millions of times.
When a new version of javascript is released it is not certain that all browser manufacturers will adopt it or even part of it. If you are going to learn Javascript and then later use it to write ASP.NET then you may want to add Jscript to your list of needs.
Where as javascript has been thought of as a toy filled with security risks earlier. AJAX popularity is making it known that javascript has matured and is ready to take on the hard jobs. It is also showing those that said javascript is not a real programming language that they are wrong. But while AJAX is doing a lot of good it also presents newcomers with an extra layer of information to learn. But don't worry once you learn javascript you may be able to write your own ticket and make programmers of those "hardcore" languages jealous of your payrate.
When you are learning a programming language you are going to make mistakes. Those mistakes should be made apparent by some tool or error handler (exception handling) built into the language itself. Javascript has no built-in error handlers and finding a good tool to debug code with is next to impossible.
Venkman the Mozilla javascript debugger is one of the most difficult to use pieces of software around. It lacks user guides, a friendly GUI and pretty much sucks. The IE script debugger is also junk that always seems to popup at the wrong times.
The old school Netscape javascript debugger was the best around. Unfortunately it disappeared when Venkman showed its ugly head.
There still is no cross-platform open source debugging tool for javascript. As AJAX becomes more popular and with it more professional programmers moving to javascript, you will see this become the number one complaint. The only open source debugger worth talking about is Firebug, a Firefox extension which seems to be fairly straightforward in usage. But as good as it is it cannot tell you if an error occured because of the web browers interpreter or a coding error in anything but the Firefox web browser. If you are a Mac user you can use Safari enhancer to bring forward the debug menu which is carefully hidden. You may want to hack it yourself by typing the following command in Terminal (while Safari is NOT running):
% defaults write com.apple.Safari IncludeDebugMenu 1
You will have to learn to ignore things like this because they are common in the world of javascript. Opera does not have a javascript console in its latest release despite the claims on their website. It would be my guess that it is now called "error console". Opera never seemed to put much interest in javascript and it shows.

Because debugging is such a pain creating javascript applications using a library may be the future. With a library you leave most of the debugging up to someone else. All you have to know is what web browsers the library supports. But here again it is good to know javascript and having to learn a library like Dojo,JQuery or Mochikit adds to the learning curve. Rest assured Mozilla will soon create its own framework or library and make things "better"?.
As mentioned earlier all browsers handle javascript differently and not every browser sends an error message. Given the number of web browsers available learning how each of them behaves to javascript code is punishing. Especially if you do not have access to other operating systems where javascript may perform differently than it does on Windows browsers, Linux and Mac browsers have to be accomodated. This means that you will have to be dependant on others for troubleshooting. Play nice with the people from the other OS gang.
To do javascript properly you not only have to know the language but also a thick slice of hacks. Being familiar with the DOM of the major browsers and possible hacks so that you can give cross-browser compatibility to your applications. Using a framework may save you from this but it is good to know in any case. You may find yourself trying to hack a framework someday.
There are really no good books about javascript. Danny Goodman's Javascript Bible is the only one that I have used where the examples work. It also has the least number of typos. When it comes to documentation it is a free for all. Finding documentation on what different browsers support and how they implement the ECMA standards is not going to happen. There is not much to find even at the websites of the more popular web browsers.
Gaining knowledge from a good community of javascript users is your only hope of really learning. While a book and documentation may help they only go so far and when things get sticky you'll need a friend. You pretty much have to rub elbows with others that have been through the mill. Long time javascript gurus are not easy to come by so if you find yourself in a conversation with one then give them lots of respect. The same respect you would give Chuck Norris while participating in a bar fight.
You will never learn javascript unless you use it. It is probably the most hands on language of them all. It requires that you get your mind dirty with code and be frustrated several hours a day. It is punishing but worth it. After a few months you will feel more satisfaction from learning javascript than you would from any other language.
If none of the above list scares you then you are on your way to becoming a javascript hacker. If you are already a javascript guru then please post some of your resources for learning.
One last tip. If you are going to use javascript then blog about it. You never know what may come out of writing your thoughts out in a textarea for the rest of the world to see.
Happy Publishing!
I think you mean “MochiKit”, not “Mochakit”.
I have been avoiding coffee for 5 weeks now. I think that was a Freudian slip. A Caffe Mocha would taste so nice right now.
Testing
Sorry, I have to disagree with some of these comments, but appreciate the time you spent writing this article.
First, with documentation, the main pages I use are:
http://developer.mozilla.org/en/docs/DOM
http://developer.mozilla.org/en/docs/DOM:element
I would also suggest that you install the ‘WebDeveloper’ Fire Fox extension, where on the ‘options’ dialogue, under ‘Miscellaneous’ you can ‘Enable strict JavaScript warnings’… by spending the time to fix ALL errors that come up (in the standard, built in ‘JavaScript Console’ under the ‘Tools’ menu), usually fixes most problems.
http://chrispederick.com/work/webdeveloper/
You should also learn how to use the Firefox DOM inspector, either the built in one (on MS Windows you have to use the ‘Advanced’ install to enable this), or you can use the alternative in FireBug. Although I personally prefer the default one… but that could be because I’ve used it for years. The real trick with this DOM window is the icon top left (small icon of a mouse), you click on it, then on the element you want to inspect on the page, return to the DOM window and use the little drop down menu on the right panel to expose all of the JavaScript/CSS/Computed Style values.
FireBug has an amazing ‘console.log()’ function, which really beats the hell out of using the ‘alert’ function… but again, I rarely have FireBug open… not sure why though.
Operas JavaScript (Tools > Advanced > JavaScript console on OSX) isn’t pretty, but works really well… if you have errors being thrown up in it, then perhaps its a problem in the code (its usually the case for me).
Learn that IE5+6+7 is rubbish… yes you need to hack the odd thing (like the ‘hand/pointer’ css value for IE5), but if you keep to getElementById(), it solves allot of problems (never use the old school ‘document.all’)… but keep in the mindset that if something does not look right, its a problem with IE (90% of the time that’s the case), this way you can spend the time finding alternative solutions.
Continued…
…Continued
Get into the habit of using unobtrusive JavaScript, so that people without it (google spider) can still use your website… use JavaScript to enhance the page, not as a requirement.
http://onlinetools.org/articles/unobtrusivejavascript/
Libraries are good, but I find that that they start creating a ’smoke and mirrors’ problem, where by you (the developer) have no idea what’s going on inside them. Personally, if I find something I like in a library, then I extract that part into a stand alone script so I know what’s going on and don’t have a dependancy on other developers to get it right (i.e. if there is a problem with the library, who and when will it be fixed?).
http://web-graphics.com/2006/05/23/on-modifying-prototypes-of-javascript-built-ins/
If you are happy with the basics, have a look at closures… they will make your head spin at first, but there really cool (and can really piss off IE, and its higher than ‘normal’ memory leak problems).
http://www.jibbering.com/faq/faq_notes/closures.html
And as a last resort, there is always Google… :-D
So sorry for bashing your article, I really do appreciate that you went to the time to write about it.
Craig
PS, your site seems to be throwing up the error ‘Terminated request because of suspicious input data’ quite allot… worrying… it seemed to be choking when I wrote “alert” followed by “()”.
You are allowed to disagree. That’s the fun part. Thanks for the tips and input.
The errors are caused by the input filters placed on anonymous posts. The common spam and hacking stuff. Those with author roles are able to post unrestricted.
You can blame IE5/IE6/IE7. That’s irrelevant. The point is that it’s not a cakewalk, regardless of what the reason is.
Next time someone says that JavaScript is not a real language, ask them to show you the most complex JavaScript file they’ve ever written. After hearing their excuse, show them this 1,785 line JavaScript file:
http://demo.vegui.org/ui/demo.js