Lesson 1: What is JavaScript?

By Maria Antonietta Perna

The first thing that creates some confusion about JavaScript is its name. In fact, one of the most common questions students raise when approaching JavaScript is:

"Is JavaScript the same as Java?".

Clearing up this basic but important question is our first order of business in this lesson, but by no means the only one. By the end of this lesson you will also know:

  • the difference between JavaScript and Java;
  • what JavaScript can and cannot do.

Are JavaScript and Java the same thing?

No, they are not.

Java (developed by Sun Microsystems) is a powerful and much more complex programming language in the same category as C and C++.

JavaScript was created by Brendan Eich at Netscape and was first introduced in December 1995 under the name of LiveScript. However, it was rather quickly renamed JavaScript, although JavaScript’s official name is ECMAScript, which is developed and maintained by theECMA (European Computer Manufacturer's Association) International organization.

JavaScript is a scripting language, that is, a lightweight programming language that is interpreted by the browser engine when the web page is loaded.

The fact that the JavaScript interpreter is the browser engine itself accounts for some inconsistencies in the way your JavaScript-powered page might behave in different browsers. But don't worry: thankfully, well-established techniques and powerful JavaScript libraries such as jQuery (which will be introduced in later lessons) are here to make things wonderfully easier on us.

Things you can't do with JavaScript

You can't force JavaScript on a browser.

Illustration: No JavaScript supporting browser

JavaScript runs in the client, that is, the brower. If you use an older browser without support for JavaScript, or if you simply choose to disable JavaScript in your browser, then a JavaScript script can't work.

Conclusion: unlike what happens with languages that run on the server, such as PHP, you never fully know for sure the impact that the browser your website visitors are going to use will have on your script, or whether your visitors will choose to turn JavaScript support off.

You can't access or affect resources from another internet domain with JavaScript.

Illustration: Crossdomain not allowed in JavaScript

This is called the Same Origin Policy. Well, how would you like it if all of a sudden all the nice comments your visitors left on your website started to disappear, or to change place in your page because of a naughty JavaScript script running on another website?

This is exactly the kind of nasty situation that the Same Origin Policy is designed to prevent. Conclusion: your JavaScript script can only access resources in your website.

You can't access server resources with JavaScript.

Illustration: Server access not allowed in JavaScript

Because JavaScript is a client-side language, it's limited to what can be done in the client, that is, usually in the browser environment. A JavaScript script cannot access server resources such as databases.

Zillion things you can do with JavaScript

With JavaScript you can:

 - Put text in an HTML page on-the-fly.

Say you want to display a nice thank you message to a user who has just submitted a comment form on your website. Obviously, the message needs to be added after the user has submitted the form.

You could let the server do that. However, if your website is very busy and your server processes hundreds of forms a day, it might take a little while for your thank you message to appear to the user.

Here's JavaScript to the rescue. Because JavaScript runs in the user's browser, the thank you note can be added and displayed on the page almost instantaneously, making your website users happy.

 - Make your web pages responsive.

Web environments are dynamic, things happen all the time: the web page loads in the browser, the user clicks a button or moves the mouse over a link, etc. These are called events (which will be the topic of lesson 3).

With JavaScript you can make the page immediately react to these events the way you choose: for example, by showing or hiding specific page elements, by changing the background color, etc.

 - Detect visitors' browsers.

You can use a JavaScript script to detect the visitor’s browser, or, even better, you can detect what features a certain browser does or does not support. Depending on the browser and its capabilities, you can choose to load a page specifically tailored to that kind of browser (lesson 14).

 - Create cookies.

A JavaScript script is great if you want to create cookies so that your visitors can enjoy a personalized experience the next time they visit your website (lesson 15).

 - Validate web form data.

You can use a JavaScript script to validate form data before the form is submitted to a server. This saves the server from extra processing (lesson 16).

And much ... much more.

Learning JavaScript will enable you to add cool animation effects to your web pages without using an external Flash plug-in, use the newest features of HTML5 such as canvas (to draw directly on your web page) and drag and drop capabilities, integrate your website with external web services such as Facebook, Twitter, etc.


In this lesson you learned what JavaScript is, who invented it, and that the body responsible for its maintenance and continuous development is ECMA. Now you know what you cannot do with JavaScript, but also the great things that you can do with it.

At this point you might say:

"That's all well and good. I'm convinced, JavaScript is fantastic. But, how can I start using it in my HTML page?"

That's easy: learn how this is done in the next lesson.

Related topics in the RepliesViews
No related topics yet

+ Post a new topic

<< Introduction

Lesson 2: Your First JavaScript >>