Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

language="javascript" vs. type="text/javascript"

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?

like image 785
Foo Avatar asked Apr 12 '13 15:04

Foo


People also ask

What is type text JavaScript?

The HTML <script> type Attribute is used to specify the MIME type of script and identify the content of the Tag. It has a Default value which is “text/javascript”. Syntax: <script type="media_type"> Attribute Values: It contains a single value i.e media_type which specifies the MIME type of script.

Should I use type text JavaScript?

No, it is not necessary if you use HTML5. "Differences Between HTML 4.01 and HTML5 In HTML5, the type attribute is no longer required for JavaScript. The default value is "application/javascript"." Source: https://www.w3schools.com/tags/att_script_type.asp To use HTML5 write <!

Which of the following scripting type does JavaScript use?

In a nutshell, JavaScript is a dynamic scripting language supporting prototype based object construction. The basic syntax is intentionally similar to both Java and C++ to reduce the number of new concepts required to learn the language.


1 Answers

<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.

like image 149
Rocket Hazmat Avatar answered Sep 25 '22 12:09

Rocket Hazmat