You are currently viewing the BOOK: Beginning JavaScript 4th Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
Is the "type" attribute important enough to basically always include in your opening <script> tag, or can it be optional these days. I've heard a couple different opinions on this - both strict and non-strict views actually. What's the best practice in majority of serious professional work environments?
If validation is important to you, and your documents are HTML 4.01 or XHTML, yes, type is required. If your document is HTML5, then no.
The type attribute was important a few years ago because without it, Internet Explorer had to guess what scripting language you used in a particular script element. Since IE7 or IE8, the type attribute defaults to text/javascript. So ultimately no, it's not required (unless validation is important to you).
Thank you for a typically clear explanation, and thank you for the very thoughtful sequence of instruction in your book, and the lucid prose that makes it such a terrific book!