Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

66 CHAPTER 3 Getting started with JavaScript


Lesson 1: Introducing JavaScript


This lesson presents a great deal of the JavaScript language. Although much of the con-
tent exists in previous releases of JavaScript, all content in this chapter is part of the latest
JavaScript specification.

After this lesson, you will be able to:
■■Define JavaScript variables.
■■Create JavaScript statements.
■■Create function declarations.
■■Create function expressions.
■■Convert objects to a different type.
■■Write conditional statements.
■■Write looping statements.
■■Handle errors.

Estimated lesson time: 60 minutes

Understanding JavaScript


JavaScript is not related to Java, although it is a curly-brace language like Java, C#, C++, and
many other programming languages. JavaScript is related to ECMAScript, however. Ecma
International, working with other organizations, created this standardized scripting language
in the ECMA-262 specification and ISO/IEC 16262. The language is widely used for client-side
scripting on the web, and you commonly see several well-known variations of ECMAScript
such as JavaScript, JScript, and ActionScript. The current release is ECMAScript Edition 5.1 and
most common browsers support ECMAScript Edition 5.0 or newer.
JavaScript is untyped, which means that when you create a variable, you don’t need to
specify its type. This might seem like a feature because you declare a variable with the var
keyword and assign a string to the variable, and later, you can assign a number to the same
variable. However, it’s difficult to apply Microsoft IntelliSense to untyped languages. It’s also
difficult to maintain the code because it’s difficult to know the variable’s type. This might
cause you to develop an immediate dislike for the language, but persevere and work with the
language. You’ll be amazed at the power of JavaScript. Although you might never want to
trade in Visual Basic .NET or C#, you’ll find that the more time you spend with JavaScript, the
more respect you’ll develop for this language.
One way to ease the pain of learning JavaScript is to make sure you are using tools that
can help you. The latest release of Visual Studio 2012 adds more IntelliSense to JavaScript and
Free download pdf