Javascript is used to execute logic in your webpage.
For instance, let's say you have a text box on your webpage in which the user is supposed to key a number before they submit the form. But some goofball keys the word "hippie" instead, and then hits the "submit" button.
Well, your server side code (PHP, or ASP, or JSP, or OWA, or Cold Fusion or whatever ... ) probably catches the error and sends the webpage back to the use with a message like, "Please Enter Numeric Data Here".
Well, that's okay, but you've wasted alot of time sending the web page back to the server, and then sending right back to the user. Plus, if there are other fields the user might have filled in, you have to make sure to put those values back when the webpage is sent back to the user.
Javascript, on the other hand, can do things like check text boxes to see if they have numeric data, and can prevent the form from submitting AT ALL, and can pop an alert box on the screen to tell the user what the problem is. This is much faster than waiting for the server side code.
Javascript code can be run when fields or buttons are clicked, or even on "mouseover" events. It can make objects (like buttons or pop-lists) visible or invisible depending on what else goes on in a form.
Like a regular programming language, it has loops, conditionals, mathematical operators, the ability to run other blocks of JavaScript code (they're called "functions" whether they return a value or not), and pretty much everything else a programming language can do.
Javascript is really very useful for making your web pages react to what a user is doing. I've never written a webpage that doesn't make EXTENSIVE use of Javascript.