How To Start Off Your JavaScript Code

By: Dusty Arlia
Published on June 27, 2012
Last Updated on February 11, 2013
Total Updates: 4

Whenever you start your JavaScript code, you can do this: <script type="text/javascript">. If you are using HTML 4.01, XHTML, or HTML5 (which you most likely are) then you don't have to use the type attribute. The only downfall will be that your code will not validate using the W3C Validator.

Your version of HTML is indicated in the doctype tag. The HTML5 doctype tag should look like this: <!doctype html>.

With most websites using HTML5 today, leaving out the type attribute is the most common choice. Just put your JavaScript code in between the opening <script> tag and the closing </script> tag.