Watching:

JavasScript: A Basic Introduction and Overview


show more Before you start writing JavaScript, it's important to understand the core concepts underlying the technology. Learn how JavaScript interacts with HTML and CSS, what terms like scripting and client-side language mean, and how JavaScript has become one of the most stable, cross-browser compatible programming languages. Plus, learn why JavaScript is a great choice for new developers who are just learning how to program: there are no special tools required to get started writing JavaScript. show less
please wait ...

Introduction to JavaScript

So before we start writing some JavaScript, let's get some core concepts cleared up. It's very common to see JavaScript referred to as one of the three core languages of web pages. You have the HTML markup language for content and structure. What's your headline, how many divisions are in your page, how many paragraphs do you have, what are the contents of those paragraphs? Then the CSS, the style sheet language, for presentation. What font does the headline use, what's the background color of the page, what's the width of the div that the paragraphs are in? And JavaScript, the programming language for your behavior and interactivity.

What happens when you mouse over a menu, what happens when you type the wrong value in a form field, how long does a photo slideshow take to move from one image to the next? JavaScript is a programming language that you'll often hear it referred to as a scripting language, and sometimes you'll hear some software developers dismiss JavaScript as just being a scripting language. And what they mean by that is that JavaScript is intentionally limited. I can't write a desktop application in JavaScript the way I might do with C++ or Java or .NET or Objective-C.

JavaScript only works inside another application, the web browser. Whether that's IE or Safari or Firefox or Chrome or Opera, they all have a JavaScript engine inside them. The operating system runs the web browser, the web browser contains a page, and the page contains the JavaScript. Now another way JavaScript is limited is that yes, it doesn't have access to the file system of the computer that it's running on. There are no words in JavaScript to open or save local files because that would be a security risk.

There are no words in JavaScript to talk to a database or target a USB port. And that strikes some software developers as odd because most languages are all about input and output, and JavaScript isn't. But of course, they're missing the point. JavaScript wasn't designed as a general purpose programming language; it was designed to manipulate web pages and it does that very well. Now as you know, when a user opens their browser and requests a page from your web site, they're just send HTML and CSS as plain text, and you let their browser take care of interpreting and rendering it however their browser wants to, whether it's mobile, whether it's on a laptop or a desktop, and it's the same with JavaScript.

JavaScript is a client-side language. It is sent to the user's computer and it runs there. That's as opposed to server-side technologies like PHP, ASP.NET, Ruby on Rails. They'll execute their code on the web server and deliver the results to the client. But with JavaScript, we just send our code to the client and we let them run it. I'm going to just interject a side note here. JavaScript was designed to run as a scripting language using a web browser as a host program.

That's why it was invented. But because it has become so popular, it has in recent years popped up as a scripting language in other applications, and even in server-side products. So you'll find it in things like Adobe Acrobat and Photoshop. JavaScript is in server-side products like Node.js and Google Apps Script. But in this course, I'm not focusing on those uses of JavaScript. I'm talking about classic JavaScript, a client-side language used to add interactivity to web pages. Now if you're interested in JavaScript for any other reason, use this course to learn the core of the language, and then you can jump into those other applications.

So back to talking about JavaScript as a client-side language. One impact of this is that because JavaScript is sent to the client, to the user, is what if the user has disabled JavaScript in their browser? Well, then we can send it over, but it won't do anything. It will be as if the JavaScript never existed. Now while this situation is less common these days than it used to be, that does mean we need to do our best to write web sites that will work whether or not JavaScript is enabled. But yes, we want to add all of this cool functionality, but if the user doesn't have JavaScript, the web site still works.

It might have more limited interactivity, but it's still perfectly usable. Now another issue can be the variety of browsers out there. Just has different browsers can render and display web pages differently, usually because they don't handle CSS exactly the same way, what happens if they handle JavaScript differently? Well, this was one of the reasons why JavaScript had a bad reputation for a long time. Go back a few years and a lot of JavaScript had to be written to detect the browser and handle different browsers in different ways.

And I'm very happy to tell you that's not really an issue anymore. There are a few edge cases, but typically we don't care what browser the user has. And to understand why, let's do a super-quick history lesson here. So JavaScript was developed in 1995 by Brendan Eich at Netscape, and it first became built into a web browser with Netscape 2. It was originally going to be called LiveScript. But because Sun's Java language was the new big deal at the time, Netscape and Sun had an agreement to rename LiveScript to JavaScript to jump on that popularity bandwagon of Java.

And most people these days agree this was a bad idea and caused a lot of confusion. The two languages have nothing to do with each other. If you're brand-new to programming, they might look a little similar to you, but that's because they both really look like C. So JavaScript is not Java. It is not a light version of Java. It was not based on Java. It doesn't matter if you know Java, and we will talk no more on the matter. Now as it became popular in Netscape, Microsoft then made their own version for Internet Explorer.

They couldn't call it JavaScript, so they called it JScript, and we had more browser differences to deal with. And what happened, thankfully, then was that Netscape submitted the language to the ECMA or ECMA standards body to create an independent and officially standardized edition, and they did. The standardized edition of this language is officially called ECMAScript, and it was first published in '97. And really what we're doing in this course is ECMAScript. That's a name by a committee, so everyone just called it JavaScript, even though Mozilla officially owned the JavaScript name.

Now ECMAScript has had a few different editions, but the one we care about is edition 3, which may surprise you. It was published way back in 1999, but that's the one that you can reliably assume full support for in every major browser, and it's the one we're going to focus on in this course. ECMAScript Version 5 was published at the end of 2009 and adds a few features to the language, particularly in the advanced area.

But I'm recording this course in mid-2011. ECMAScript 5 is only now getting some support in the most recent browser versions. Adoptions of standards like this take years, and yes, at some point in the future ECMAScript 5 will be the standard, but it isn't yet. And just to let you know, compatibility was a big deal in development of ECMAScript 5, so everything we do in this course will be compatible moving forward and it will also work in all the older browsers for many years to come. Now if you're wondering what happened to ECMAScript 4 in those ten years between edition 3 and edition 5, well it just got way out of hand and they abandoned it; ECMAScript 4 never happened.

Now, one of the benefits of having a standardized language like this is it doesn't matter if you're a Mac, PC, or Linux person, it doesn't matter if your server is Windows or Apache, if your backend is PHP or Ruby on Rails or ASP.NET or ColdFusion or none of the above; JavaScript is completely agnostic on these matters. There's no special tools required. There's no licensing needed. Sure, as with editing HTML and CSS, some applications may make our life a little easier, but all we really need is a basic text editor.

Introduction to JavaScript
Video duration: 8m 6s 5h 31m Beginner

Viewers:

Before you start writing JavaScript, it's important to understand the core concepts underlying the technology. Learn how JavaScript interacts with HTML and CSS, what terms like scripting and client-side language mean, and how JavaScript has become one of the most stable, cross-browser compatible programming languages. Plus, learn why JavaScript is a great choice for new developers who are just learning how to program: there are no special tools required to get started writing JavaScript.

Subjects:
Developer Web
Software:
JavaScript
Author:
please wait ...