For adding JavaScript to HTML, I have seen people use
<script language=javascript>
and
<script type="text/javascript">
It doesn’t seem like whether the script is embedded or external influences this decision.
Which one is preferred and why?
For adding JavaScript to HTML, I have seen people use
<script language=javascript>
and
<script type="text/javascript">
It doesn’t seem like whether the script is embedded or external influences this decision.
Which one is preferred and why?
<script language="javascript">
was used in very old browsers, and is deprecated.
<script type="text/javascript">
is the HTML 4 standard.
In HTML 5, the type
parameter is optional (text/javascript
is the default), so you can just do <script>
.
As a neat hack, if you put an invalid type
, the script won't be ran, but you can still read the data in JavaScript. Some template libraries do this.
The language
attribute is deprecated. Use type
only. You don't need to specify type
in HTML5, it's javascript per default.