6

Are there any important differences between declaring <script type="text/javascript"> </script> and <script language="javascript"> </script>?

(Note I'm not asking about these declarations vs. the blank "<script>" tag)

amindfv
  • 8,438
  • 5
  • 36
  • 58

5 Answers5

18

Use <script type="text/javascript"> or simply <script> (if omitted, the type is the same). Do not use <script language="JavaScript">; the language attribute is deprecated.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
6

The language attribute was used when <script> was introduced in HTML 3.2 and took a language name (such as JavaScript). The type attribute replaced it in HTML 4.0 (as everything describing non-HTML media started taking MIME types) and takes a MIME type (such as text/javascript). More recently it also supports the special value module for JavaScript modules (which support the import keyword).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
2

<script language="javascript"> </script> is deprecated and shouldn't be used anymore.

<script type="text/javascript"> </script> is the current (HTML4) way to do it.

If you have an HTML5 DOCTYPE, you can just do <script> </script>.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
2

Language is generally used to indicate the Javascript version that your script requires. Browsers that support the language attribute won't load or run the script if it doesn't support it. About the only use would be if you had critical Javascript functions where you needed workarounds for older browsers.

Matt H
  • 6,422
  • 2
  • 28
  • 32
0

I think <script language="JavaScript"> not passes validation HTML 4.01. Type attribute is required.

Alex Dn
  • 5,465
  • 7
  • 41
  • 79