The way to become a good programmer is to have projects that drive you. So build stuff. You'll find you learn very fast when there is something specific you want to do and you don't know how. So you should read books, certainly, but don't just work your way through books.
It doesn't matter super much what language you learn initially. So if you have some friend who is an expert in another language, you might be better off learning that, then switching to Javascript once you know the basics of programming.
Get Firebug and play with it. (You probably know this, but just in case...) Firebug is a Firefox plugin with a Console tab that lets you enter any Javascript you want and shows you what it evaluates to. If you type 2+2, it will say 4, and so on. It will also let you explore the internals of web pages and fiddle with them to learn how they work.
The best way, in fact the only way, to learn programming is to read and write a lot of code. An interactive environment like Firebug makes that easy. If I were you, I'd get myself a good Javascript book and type in the examples as I read them. Then I'd try modifying them to do cool things. Good luck!
Edit: when you get stuck, ask questions. I taught myself programming when I was your age and my biggest obstacle was not having anyone around who could help me when I got stuck. Nowadays that's not a problem since there are lots of people on the web who are happy to help.
+1 for Firebug. Getting out of my Python comfort zone and writing Javascript used to be scary. But now that I have an awesome debugger and the ability to experiment at runtime (and jQuery) I feel comfortable writing enough Javascript to make my applications suck less.
+2 for Firebug. Firebug should be your number 1 priority to get familiar with.
jQuery... I have mixed feelings about it.
On the one hand, its very good for high level thinking and writing good, readable code. On the other hand, it slows down your javascript code by at least 2x, which is particularly noticeable if you're doing a javascript intensive application. Then again, the future of browsers is speeding up javascript, so this may not be an issue in a couple of years.
My experience with Prototype is that it handles the speed issue much better - however, it is a bloated monster of a framework.
I usually approach JavaScript frameworks the same way I approach high-level languages: write the app in whatever way is most convenient, then profile and rewrite the performance-critical sections without the framework. I've never had performance problems with JQuery, because I usually just write my mouseMove handlers so that they operate on the raw DOM without it.
(I wrote something to this effect on Proggit once, and John Resig reply was something like, "Of course. JQuery's not intended for performance-critical code - usually you don't want to be using any framework for that. JQuery's meant to make the other 90% of JavaScript development go faster.)
BTW, I won't go near Prototype (after having used it pretty extensively at a past employer) because it messes with Object.prototype. When libraries do that, you have no way of knowing which libraries are compatible, which means that you'll suddenly get bitten by very odd, hard-to-track-down bugs.
I should say that /any/ framework is not intended for performance-critical code. A framework is designed to be an abstraction - abstractions implicitly remove you from what you're trying to do, causing a performance hit of some sort. If performance is your #1 priority then you should be writing everything from scratch.
Now if development time is a greater priority over performance then I think the choice is pretty obvious.
I don't do intensive enough work, or know enough about Javascript frameworks, to notice speed issues. I generally use it to update a div with the results of an ajax call, to asynchronously submit a form, and to manipulate some UI elements: alternate row striping, show or hide, change the size of elements, etc.
I don't pretend to know what I'm doing with JS, so I'll keep your advice in mind should I have to figure out why something isn't as fast as it should be.
Hmm. My understanding is that it strips out a bunch of unnecessary (correction: able to be simplified, not necessarily "unnecessary") elements and makes it easier to write leaner JavaScript. Also easier to have a browser render JavaScript.
1) The #1 secret to good JS is mastering crazy-yet-delicious object-orientated prototype madness. You won't get anywhere just learning how to write functions, but learning how to use prototyping well is a esoteric skill, so that's where Crockford comes in:
2) Check out the videos on http://developer.yahoo.com/yui/theater/ There's 2.2gigs of them for you to digest. Crockfords are especially good, and will teach you good practices.
3) Use a framework like mootools to save you time on real projects. However, I advise against assuming these frameworks are "perfect"; they all have faults.
4) Don't copy other people too much - many JS devs, including me, are terrible programmers :-P
5) Learn JS by creating AJAX projects as it's so important to web apps. "Professional Ajax" by Zakas is a decent place to start.
6) Enjoy it! JS is a fantastic language, and the quick returns can be incredibly rewarding. It has its faults, but it is amazingly powerful and quite unique.
Don't copy other people too much - many JS devs, including me, are terrible programmers
One of the biggest problems with JavaScript is its community. I'm not talking about N.YC readers who think they are bad programmers. No, I'm talking about the fact that there are reams and reams of plain old bad advice on JavaScript out there that still outrank the good stuff in most search engines.
99% of the time a Google search on a JavaScript problem will score you pages of hits with antiquated, non-standard, buggy or IE-only approaches.
You won't get anywhere just learning how to write functions
I totally disagree. Learning how to write functions is a big, big deal and will take you far indeed. I can't think of anything more important for learning programming.
Meanwhile, "object-orientated prototype madness" is entirely optional.
6) Go to school, even when you are not going to learn Javascript there, you are going to learn a lot of things that are very important for your projects too.
The learning will not come to you, you need to go out and get it. Don't just go to school, attack school, suck the juice out of the fruit, and have fun doing it. Make it fun and hard.
(Note that to become the best JavaScript programmer ever, you'll probably have to pick up some other languages along the way. But JavaScript is both a good language to learn and a good language for learning, so it's not a bad idea to learn JavaScript really well first before learning others. Keep an open mind.)
Another great place to start is Jeremy Keith's DOM Scripting book (published by Friends of ED), it's really well written and a great introduction to unobtrusive, clean Javascript. There's a sample chapter on his site: http://domscripting.com/book/
On a side note, don't learn a library as the first thing you do as you'll be learning how to code in jQuery, Prototype, etc, rather than in Javascript.
I started learning programming at 12 years old. An ideal year in my opinion. Experiment with everything you have the time to learn about. You may be surprised at what you can do with an otherwise bland tool or function.
I know there's some redundancy in this advice but I thought I'd mention it to support the great tips already here.
Practice. Read and write a lot of code. You might try to work your way through set problems like Project Euler or the Ruby Quiz or other competitions.
Learn the "laws of physics" of programming - some things are harder to do than others. all programming is an interplay between making a tiny, trivial and deterministic step on one hand and managing complexity through abstraction on the other.
it's most instructive to try things for yourself - even if you fail - but on the other hand make sure you attempt things you will definitely succeed at too because the feeling of success will fuel your passion. you will never be a great developer without passion!
Watch Douglas Crockford's JavaScript videos.
use Flanagan's Rhino book.
Try and use different programming patterns and styles in javascript: imperative, functional, object oriented, continuation-passing, dependency injection, fluent interface.
Always use var and semicolon.
Never use "with" or "eval".
Plan to learn another programming language (which smart people recommend you) and it will also greatly assist your javascript programming - you should not be too tied to a single language that you can't change. If you really like web 2.0 you should learn a good server side language as well. As a second to JavaScript for a youngster I would recommend Ruby or Python, (or PHP if you must). Other languages are really great for that purpose but these will be easier to learn first and will be readily available on cheap hosting providers. Those others may include: Lisp/Scheme, Smalltalk, Java, C#, Scala etc. Do not learn VB.
Get firebug.
Read "The Pragmatic Programmer".
Reuse code.
Write automated tests. You can use a unit test framework.
Write lots of cranky cryptic puzzle code right now. Get it out of your system. Then seek to write clean comprehensible code forever more.
Port code from another language.
Recognise that lots of people in professional development have absolutely no idea what they're talking about. Others are absolute genius gurus who's words you should memorise and meditate on. Good luck telling the difference!
Ignore what others say about your interests, put your head down, do a bit of hard work (but mostly play,); get involved in communities (eg, your favourite javascript library's community), get recognised for your work, learn from the masters, but don't ask for answers, ask for tips.
That's all I could say, I'm 16, and currently working along side some very cool people. I've been in it about 3 years.
I hope you understand that while javascript has its uses, most web applications are built on server side scripting languages. Much to the chagrin of the hackers here at YC, I personally would recommend learning PHP or Python. Probably PHP though. (Cue Ruby fanboys and anti-php lynch mobs). Really, it is the place to start if you're interested in Web 2.0 application development. Javascript is a tool you can pick up later that allows you to do cool things with your site. But I mean, wouldn't you rather jump right into doing things right? Starting with javascript will end up being sort of like...taking a class in school; you have to learn a bunch of things first, figure out something to make, embed with HTML and toy around and in the end, do you even get anything functional? How bland is that?! Now, if you start with a server side scripting language, you get your "hello world" experience and you jump right in.
To become the 'best' Javascript programmer you'd probably need to know everything about Javascript. Also you'll need to know its limits. To know its limits you should probably learn about other things that aren't Javascript but closely related to it eg other programming languages, web browsers, HTML, DOM etc.
these are wat i did (you may not know enof from that site)
-a personal greeter- a form that lets people write thier name is a box clik a button and it displays a greeting w/ thier name included in it
- a coin flip script.- that displays a RANDOM heads or tails alert
-a dice roll script- that display a RANDOM number 1-6
-any of your ideas
In addition to all those other things that people mentioned, write a JavaScript interpreter.
You can't truly master a language until you know it inside and out. Implementing the language is a great way to do that. That's how I learned ML and Haskell. That's how I'm learning Lisp.
One of the most difficult parts of JavaScript and web 2.0 is getting things to work on all the different browsers. Install the most recent versions of the most widely used browsers: http://www.w3schools.com/browsers/browsers_stats.asp
Good luck man. I've been programming all my life and still love it. Javascript is a great language to dive into.
Always be working on a project. Come up with an idea, like tic-tac-toe and start hacking on it, until you are finished. Then cook up another idea and hack on it. Without an idea, you'll just float around. Get Firebug and learn to love jQuery, it's magic.
And if you want to be great, you don't want to be a programmer, you want to be a hacker. :)
You've already got the atitude to be an excellent programmer. Your success is assured if you learn more than one programming language. For you purposes, learn Pascal, learn C, learn Perl, learn JavaScript. This will minimise your learning curve and risk of failure while giving you increasing power and understanding.
A langauge with strong typing and bound checking is ideal when you're learning algorithms. A newbie coding a bubble sort in Pascal encounters less mysterious failure modes than a newbie coding a bubble sort in C. (Consider the off-by-one gotcha at the end of the inner loop.) I know that strongly typed languages are unpopular on this forum and I've been downmodded for mentioning one. However, consider the suggested progression of languages to be like riding a bicycle and then having the training wheels removed.
I don't have direct experience of ML but I'd definitely recommend against Java because there's a tsumani of information. It is overwhelming for a newbie. Pascal is small and concise. The grammar is unambiguous. You know when you've outgrown it and you'll move on. When you master Pascal then C looks trivial. When you master C then Perl looks positively slack. This can be done while minimising information overload.
Much respect to you, young coder! I avoided Javascript for far too long, but when I needed to learn it, the o'Reilly Javascript & DHTML cookbook was a great resource.
Firebug is nice, but Venkman's Javascript Debugger for FireFox is my favorite. The interface is a bit weird, but your mind should be flexible enough to figure it out. :)
I'd suggest learning Flex. For the longterm, I think this is the true winner.
If you are absolutely determined to learn Javascript
- I agree with others read the articles by Crockford and watch the Yahoo UI videos
- Read the code for dojo. Alex is one sharp javascript guy.
- For ajax frameworks look at DWR
I just realized that I have about 10 years to do all the hacking I want, and then the current crop of 12-year-olds will hit the market and annihilate us old guys.
His alias is "Javascripter"... he wants to be the "best in the world"... he's 12 years old... just the overall wording taunts me with a hint of spam.
I don't think a 12 yr old would have that enthusiasm for pure javascript.. would definitely ask about HTML (if he knows html he knows how to find out about javascript?)...
Well, I assume you really mean "troll" rather than "spam", and given the earnest and constructive answers he's gotten so far, I'd say that if he's a troll he's the least successful one ever :-).
When I was 14 (1995), I'd been doing shoddy programming for a couple years and read an article in Newsweek about genetic algorithms and somewhat naïvely decided to look up the guy interviewed (on compuserve) and drop him a mail (David E. Goldberg). He went to the trouble to not only answer me, but run off a huge packet of copies of articles and snail-mailed them to me. That seriously changed my life. That's when I learned what computer science really was. Answering questions like this is important, in my opinion, even if you get duped once in a while.
Learning a library is not the way I would recommend learning a language. At 12 years old, javascripter has no time constraint to build a product fast.
javascripter, learn about Javascript's language features. Learn about nested function and function passing. Learn about object-oriented Javascript and prototypes. Learn the difference between Javascript the language, and DOM, the thing within the language you use to add functionality to web pages. If you find that you are repeating things, write your own library.
Is this the first programming language you are learning? If so, it will give you a leg up when you learn a more conventional language like C or Java, because it will give your mind flexibility. If you already know a programming language, understand that different programming languages have different ideas about how programs can or should be expressed. (That's why there are so many languages.) It will sometimes be helpful to see how something in a new language is similar to a language you already know, but other times you have to just say to yourself, this is different, and I have to think a new way.
I don't believe this, at all. A JavaScript library abstracts away frustrating details that aren't related to the JavaScript language: like insane browser bugs.
Instead choosing a good library can give you free range to explore the advanced programming concepts in JavaScript, instead. jQuery, for example, is highly functional. It makes heavy use of lambdas and closures - even encouraging newbie programmers to use them.
If you want to get better at programming, through programming JavaScript, then a library is the only way that you'll be able to keep your sanity and make that a reality.
Amen. Simplifies DOM traversal, allows you to do cool things (others aren't doing commercially yet), and takes cross-browser compatibility out of your hair.
Hi javascripter. First of all, welcome to news.yc!
There's at least one thing you're already doing right: you're starting out with a problem that interests you. However, I don't think you have quite the right goal. You don't want to be the best Javascript programmer ever. You want to be the best programmer ever. Javascript should just be one weapon in your arsenal, and a rather specialized one at that.
That said, you have to start somewhere. Usually I recommend that people start with Scheme and read SICP (online at http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html), but since you've indicated that you're interested in web programming, that's probably not the right first step for you. The trouble with web programming is that it's messy. Any non-trivial website requires you to understand a whole alphabet soup of different programming languages and markup languages, some of which were designed for each other and some of which weren't, and then to top that off you get to worry about Internet Explorer dain bramage. If you're just programming for an audience of you and nobody else and you choose carefully what to work on, then you can ignore some of these issues, but sooner or later they'll leak in and it's going to seem overwhelming. (This isn't necessarily bad; coping with information overload is one of the most valuable skills a hacker can learn.)
So, here's what I suggest. Start by learning Python. It's a clean, reasonably powerful, easy-to-learn language, and it's very good for web programming. I assume you already know HTML; if not, learn that first -- it'll take you a couple days max. You can make a pretty capable website using just Python and HTML. You could almost write news.yc, except for the AJAX up-arrows which require Javascript. A site like this would be pretty big as a first project, though.
I'll let someone else recommend a Python tutorial. I just learned it from the reference manual, so I don't know a good one.
Once you feel confident making web pages using Python and HTML, then it's time to start learning Javascript. It might also be a good time to go back and learn to write standards-compliant XHTML-strict and CSS, since this will make working with the Javascript DOM a bit less of a headache, but this is optional and you can do it in parallel with learning Javascript if you do it at all.
Finally, here are some bits of non-technical reading I recommend:
My very first language ever was javascript. I completed Thau's javascript tutorial and the advanced version (both at webmonkey.com), and from there I got a really nice start (without knowing it).
If you combine a simple introduction like that with plenty of exploration with Firebug, and have a strong motivation -like making a kick-ass webpage for yourself-, you are on your way,
It doesn't matter super much what language you learn initially. So if you have some friend who is an expert in another language, you might be better off learning that, then switching to Javascript once you know the basics of programming.