Start Here! Learn JavaScript - Cdn.oreilly.com
Start Here! Learn JavaScript - Cdn.oreilly.com
Start Here! Learn JavaScript - Cdn.oreilly.com
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Script types<br />
While we’re discussing the tag, it’s a good time to discuss the type attribute, which<br />
you can see in the previous example. The type attribute specifies the Multipurpose Internet<br />
Mail Extensions (MIME) type of the script. There is a good deal of discussion as to whether<br />
the type attribute should even be used—and if it should, what it should contain for <strong>JavaScript</strong>.<br />
Some developers don’t use the type attribute at all, while others use a language attribute instead.<br />
Some developers use both a language attribute and a type attribute.<br />
There’s also confusion as to whether to use text/javascript, text/ecmascript, or the newer<br />
application/javascript or application/ecmascript as the value for the type attribute. As a Java-<br />
Script programmer, be prepared to see variations of the type attribute, to see the type attribute<br />
missing, to see the language attribute, or to see some <strong>com</strong>bination thereof.<br />
The value I’ll use throughout this book is text/javascript because, as of this writing, it enjoys<br />
the most <strong>com</strong>patibility and support across browsers. I’ve had the most success using the type<br />
attribute.<br />
No <strong>JavaScript</strong>? No problem.<br />
Sometimes <strong>JavaScript</strong> isn’t available in your visitor’s web browser. The user might be using assistive<br />
technologies or maybe she just disabled <strong>JavaScript</strong> manually. Whatever the case, the tag<br />
helps if <strong>JavaScript</strong> isn’t available in the browser. The tag is used by most web browsers<br />
when scripting is unavailable. The content between the opening and closing <br />
tags displays for the user, typically informing the user (politely, of course) that <strong>JavaScript</strong> needs to be<br />
enabled in order for the site to function properly.<br />
See Also See http://www.w3schools.<strong>com</strong>/tags/tag_noscript.asp for more information about using the<br />
tag.<br />
Writing Your First <strong>JavaScript</strong> Program<br />
In this section, you create your first <strong>JavaScript</strong> program. As a side effect of doing so, you also create<br />
your first webpage with HTML.<br />
<strong>JavaScript</strong> is tool-agnostic, meaning you can use any text editor or Integrated Development Environment<br />
(IDE) to write <strong>JavaScript</strong>. For example, Microsoft Visual Studio provides a powerful development<br />
experience for writing <strong>JavaScript</strong>. The same can be said for Eclipse, the open-source IDE. However,<br />
an IDE is certainly not a requirement for creating and maintaining <strong>JavaScript</strong>. You can also use a<br />
simple text editor such as Notepad or a more powerful text editor such as Vim to write <strong>JavaScript</strong>.<br />
You’re only a few pages into this book and you already have an important decision to make: What<br />
tool should you use to write <strong>JavaScript</strong>? The guidance I can offer for this choice is limited because I<br />
believe you should use whatever tool you’re <strong>com</strong>fortable with for programming. If <strong>JavaScript</strong> required<br />
10 <strong>Start</strong> here! <strong>Learn</strong> <strong>JavaScript</strong>