Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This question already has an answer here:

I'm a new graduate, but I have been doing web development for about six months. When I was finishing university the server side languages (PHP, Java) were more important then client side languages. JavaScript was only used to validate data or use AJAX to beautify the page. The server side validation was of course done anyways.

As I dive into more projects, I can see that JavaScript is used a lot. It's mostly to create visual effects, but an important part is used to convey data (JSON) and make requests (AJAX). In a project I'm following, JavaScript takes up 30%-40% of the codebase!

My question is: "Is JavaScript that important?".

My first impression was not good, but I also realize that it requires skill to write good JavaScript. It seems to be very easy to write, so it's so damn hard to manage and very hard to identify the flow of JavaScript.

P/s: A lot of tricks, tips, library(like JQuery) and tutorials are out there, they are a lot but I don't know the best way to start. So I'm very grateful if someone could give me an advice.

UPDATE: As now i'm on the way with javascript, thanks for all helpful advices. I will try to summarize the answers, so that it can be a good source for anyone with the same problem.

Javascript:

Why it good:

  1. Best User interface
  2. Lots of good framework
  3. Server side javascript (MongoDB & Node.js)
  4. Many success application built from it (Gmail is an example)
  5. Object-oriented able
  6. Good support (HTML5 included)

Important Concept

  1. Closure (event handling)

Best practice

  1. Nothing global. Try to use "namespaces/libraries and classes"
  2. Never function (controversial). I still use function, and it seems not very bad.

Resources

  1. Mozilla Developer Network
  2. Douglas Crockford
  3. W3Schools (starter)
  4. Tizag
  5. Javascript - The definite guide (ebook) (recommended by Douglas Crockford)
  6. Head first Javascript (ebook)
  7. Head first Ajax (ebook)
  8. Head Rush Ajax (ebook)
  9. Object-Oriented JavaScript: Create scalable, reusable high-quality JavaScript applications and libraries by Stoyan Stefanov.
  10. Javascript Koans

Framework

  1. Mootools
  2. Prototype
  3. Dojo
  4. ExtJS
  5. YUI
  6. GWT
  7. Server side: MongoDB & Node.js

Alternative for Javascript (thanks Mike Samuel)

  1. GWT : code.google.com/webtoolkit (java)
  2. coffee script (python)

Again, I want to thank you for all the answers and opinion, as I got great benefit from all of them. Still, due to the fact that I just only can accept one answer, the answer of Renesis, for his mention about closure, which is helpful for me.

share|improve this question

marked as duplicate by gnat, Martijn Pieters, thorsten müller, Kilian Foth, Jalayn Apr 9 '13 at 12:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Yes, yes it is. Aside from doing the validation-beutification part, it has some features that can take you down new no-javascript paths. See this SO question: stackoverflow.com/questions/831967/… –  Tom Jan 21 '11 at 3:48
    
Not really an answer, so I thought I'll just write it here: Don't forget that JavaScript can and has been used for server-side development. Here are a couple of examples: en.wikipedia.org/wiki/… –  jon2512chua Jan 21 '11 at 4:56
    
+1 for excellent reflection and summary on your part. –  Michael Jun 15 '11 at 3:51

8 Answers 8

up vote 16 down vote accepted

At the moment, JavaScript is essential for a web application or web site unless you are simply going to have static pages. You need to learn it.

I am a big proponent of learning the language itself, but if you must also use it practically and do not already have or need a custom framework, I would use and learn jQuery. It is a great framework in both its design and its functionality.

Make sure to learn how closures work (defined basically: functions as variables) and this will help you understand a lot of how jQuery's underpinnings work.

One important tip, that if not followed, will let code get out of control very quickly: Try not to ever use the global space for anything but namespaces/libraries and classes! (Never functions!)

share|improve this answer
    
Just curious. Do you often use closures? I can read it, but can't write. Too hard. –  Benjamin Jan 21 '11 at 5:43
1  
@Benjamin: Closures are used everywhere and understanding them is vital to professional level JavaScript development. –  Josh K Jan 21 '11 at 6:00
    
Unfortunately I disagree with the 'never functions' part, as if you're developing with ASP.NET and you need to have inline variables, then you cannot put them into external files. For example, if you have a user control that can appear 3 times on the same page, you must use say <%= txtName.ClientID %> in your javascript function to reference the control. You cannot put this into an external JS. –  SLC Jan 21 '11 at 8:42
4  
closures aren't 'functions as variables' –  FinnNk May 16 '11 at 20:32
1  
That's not being pedantic - function as a value is not the same concept at all as a closure –  FinnNk May 17 '11 at 12:03

Yes

JavaScript is absolutely essential for doing web development.

Client Side & General

I wrote a list of JavaScript best practices not too long ago, though you still have to watch out for some JavaScript "gotcha's" that sneak up. Understanding the basics of functional programming are a very good start. Keep things in local scope, create libraries to contain your objects and functions. Be consistant, use JSLint.

I recommend starting at the Mozilla Developer Network, more specifically the JavaScript section. There is a lot of really excellent information there about how JavaScript works, and common tips and advice.

Server Side JavaScript

Another thing I would highly recommend is taking at JavaScript based tools, specifically MongoDB and node.js. MongoDB is a "NoSQL" database that used SpiderMonkey under the hood to run queries and manipulate data. Node.js is enabled evented low level connections, higher level HTTP connections, and a whole bunch of other goodies for writing server-side JavaScript.

share|improve this answer

Yes

Short answer is yes, because UI matters, and it matters a lot these days, it has always mattered and it will always matter. It is not only about nifty effects anymore, better UIs make you work differently, and that matters to every user.

But wait, there is more.

Front-end applications, not decor

Before underestimating javascript (which most of us do at some point), you should know that javascript is capable of more than one might think at start. If you take a look at what can be done with javascript nowadays (aside from client-side web development) not only you will be surprised, but inspired, take a look:

Javascript is being used more and more as a backend language, just google "node.js".

Don't underestimate javascript

Even with its design flaws, developers have gotten around to build great things with it, as I exemplified earlier. To understand javascript, perhaps there is no one better to listen to than Douglas Crockford. My first serious approach to javascript, thankfully, was through this little talk by him:

"The Javascipt Programming Language" (Part 1, Part 2, Part 3, Part 4)

Personal note: I somehow managed to find that talk just at the right moment, that being already during the development of a project idea I sold and that came to production successfully... when I was a total javascript noob (at the "make the webpage ask your name and display it" level).

jQuery and Mootools

I know I might get tomatoes thrown in the face for this, but don't try jQuery before you try Mootools, why?, jQuery is popular because, in truth, any script kiddie (*dodges tomato*) can do very nifty stuff, and quickly.

The problems come afterwards, in the form of tasty spaghetti code, and that is the one thing that makes me stay away from jQuery: the code does not scale, meaning the more you add to your UI/application, the more spaghetti code you end having.

I'm not saying jQuery is bad, I'm just saying that you can do better code with other frameworks. I always recommend Mootools above any other framework, because it leads to clean object-oriented and well architected modular javascript, and in general you can say it makes javascript a better language. There is even a pure server-side javascript version of the framework of Mootools in the downloads page.

The only thing I want you to take from this is the following: broaden your spectrum before sticking with jQuery.

Some other great frameworks:

*wiping tomatoes off-face*

To understand Mootools' nature a little bit more I recommend you check the following:

Finally, remember that frameworks are only tools, not religions, you can use many at the same time, even jQuery and Mootools at the same exact time (see Object Oriented jQuery With MooTools (Pigs Take Flight)), and as any tool, it is only good if it suits your needs. If you need easy DOM manipulation and quick & dirty and/or readily available nifty scripts jQuery is for you, OTOH, if you are going to rely on javascript for your client-side application and you want a real and clean javascript architecture, Mootools is for you.

Learning it

Some resources I've found useful:

share|improve this answer
1  
You're first tomato comes from me. MooTools changes how you write JavaScript by manipulating object prototypes. Serious do not do! jQuery is great because it's a seamless addition. You don't have to learn new Object syntax, class structure, and gain a lot in terms of cross browser compatibility, event bindings, and DOM traversing. jQuery is a library, MooTools is a framework. –  Josh K Jan 21 '11 at 5:27
1  
@dukeofgaming: I explained that is't not a bunch of "no-brainer" scripts, it's a full on UI that was developed purely in JavaScript with help from jQuery for bindings and selectors. If you need something more then you don't fully understand how JavaScript works and your exposure to MooTools will limit you once you step outside that. –  Josh K Jan 21 '11 at 6:01
1  
@duke: I'll finish tomorrow, but a major point is he says "JavaScript doesn't have classes, and this is bad for a lot of developers." JavaScript is a functional prototype language, it's not designed to have classes like an imperative programming language would. Like I said, understand the core without the wrapping paper and you will be better off. –  Josh K Jan 21 '11 at 6:14
1  
@Josh There is a lot of (moot) debate about wether javascript is object oriented or not. See Douglas Crockford's word on this: crockford.com/javascript/javascript.html. Javascript is prototyped and object oriented, just not in the classical or perhaps "complete way", this is what Mootools provides; prototypal inheritance is beautiful, add the "classy" model on top of that and you've got a killer tool. –  dukeofgaming Jan 21 '11 at 6:20
1  
@Josh @duke This is an interesting discussion (wish we had somewhere to go into more detail). I agree with duke that JS is prototype OO (see en.wikipedia.org/wiki/Prototype-based_programming). Prototype-based is opposed to class-based. Interestingly Wiki refers to JS as imperative and functional. Regardless, I do agree with Josh that extending native prototypes is bad (perfectionkills.com/whats-wrong-with-extending-the-dom). Aside from those issues it's just confusing. Wrappers FTW :) –  NickC Jan 21 '11 at 18:19

JavaScript is an interpreted programming language that is mostly used to turn static web pages into dynamic and interactive pages after a web browser has finished downloading a web page. Generally, web pages should use JavaScript to enhance the user's experience, rather than depend on it. And, it's embedded in HTML pages to interact with DOM objects. Gmail uses JS as much of its interface logic in implemented in JS. And, according to Douglas Crockford (currently a senior JavaScript architect at Yahoo!), JS is World's Most Misunderstood Programming Language.

There are some other application where JS is used other than web application like Microsoft's Gadgets, Yahoo! Widgets, Google Desktop Gadgets, etc.


For learning it, I prefer Head First JavaScript. And, There is Head First Ajax and Head Rush Ajax, these are pretty enough for beginners. Have a look on them.

share|improve this answer
    
Just wanna add that JavaScript can be a compiled language as well. –  jon2512chua Jan 21 '11 at 4:57
    
May I know, Why my answer is down voted? Please leave the reason as a comment! –  Abimaran Kugathasan Jan 21 '11 at 5:37
    
Lol that wasn't me. Plus in some places ending your sentence with an exclamation mark may be interpreted as you shouting at people. –  jon2512chua Jan 21 '11 at 10:49
    
@jon2512chua : I don't mean you, just to tell the competitors to leave a comment, why they've down voted. And, I accept your argument, and removed those exclamation marks! Thanks, If I suppose to indicate you, I'll use @ sign :). –  Abimaran Kugathasan Jan 21 '11 at 11:28

If you're talking about web applications, instead of web sites, the long-term trend is to write the entire UI in JavaScript, or to write none of it in JavaScript.

The reason for this is that people have figured out that separating UI state across the client and server is awkward. As a result, there are a lot of solutions that try to bring the UI code fully onto the client or fully onto the server. If it's on the server, you end up with frameworks like ASP.NET, and you don't write much javascript code. If it's on the client, you end up with frameworks like ExtJS and Dojo, and you end up treating the server as a data store (with validation for security).

If you favor a client-centric approach, like I do, then you'll have to really learn JavaScript. Read Douglas Crockford's book, learn one of the big JS component frameworks (ExtJS is my favorite). If you favor a server-centric approach, don't bother with JavaScript. Either approach will let you build top-class web apps, but the required skillset is very different.

What I can tell you is that if you use it right, JavaScript is as clean as any other language. Many people write JavaScript as if it's PHP, throwing everything on top of a big global pile of mud. If you want to see what JavaScript can do when used correctly, look at the ExtJS examples.

share|improve this answer

Object-Oriented JavaScript: Create scalable, reusable high-quality JavaScript applications and libraries by Stoyan Stefanov.

Don't be mislead by the name, it does not assume any previous knowledge of JavaScript. It is a beginner in depth book about JavaScript (not programming beginner). I think it would be a lot more famous if not for the title.

I was facing the same choice recently and after trying a number of recommended books, I ended up reading and loving this one. The other books either assumed too much JavaScript knowledge of read like a dictionary. This one has a lot more interesting examples/problems and introduces interesting subtleties of the language explicitly to save you frustration.

share|improve this answer

You might find the Javascript Koans a fun way to learn a bit about the (good bits) of the Javascript language.

I'd love some additional koan contributions; just fork & send a pull request.

share|improve this answer

Just for fun check this link for an explanation of this bit of Javascript code

($=[$=[]][(__=!$+$)[_=-~-~-~$]+({}+$)[_/_]+($$=($_=!''+$)[_/_]+$_[+$])])()[__[_/_]+__[_+~$]+$_[_]+$$](_/_)

As mentioned in the other answers don't underestimate JavaScript, the language is remarkably powerful and because it allows the above kinds of obfuscation it does require that you take the time to get to know it. Sooner or later you may have to decipher something similar that another "clever" programmer left in some code that you have to maintain.

share|improve this answer
1  
-1. Reading a string of javascript operators on reddit and thinking it's neat isn't valid answer to this question. –  Incognito Jan 22 '11 at 20:02
    
@user1525 the question was "Is JavaScript that important?" and serendipitously reddit had a blindingly good example just why JavaScript is important and clearly you didn't even read past the 1st line of my post or you would see that I did answer his question. –  kloucks Jan 22 '11 at 20:14
2  
+1 for showing me the "annoying part" of javascript, specially, security part. But I don't want to see this in my project, for sure :| –  Hoàng Long Jan 24 '11 at 4:53
1  
I'm really sorry that you believe showing an example of obfuscation in JavaScript answers "importance of javascript and the best way to learn it?" –  Incognito Feb 1 '11 at 19:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.