What’s the difference between using type="text/javascript" or not?

Asked

Viewed 953 times

1

I’m studying Boostrap 4 and in one of the classes when setting up a carousel I noticed with the addition of type="text/javascript" to my <script>, the doubt is as follows, what is the function of passing this type and there is some advantage in that ?

Because even passing parameter the code responds the same way.

For example:

<!-- Com type -->
<script type="text/javascript">
    $('.carousel').carousel({
        interval:1000
    })
</script>
<!-- Sem Type -->
<script>
    $('.carousel').carousel({
        interval:1000
    })
</script>

1 answer

2


Until HTML4 was needed, now with HTML5 no more, stayed is optional, even to maintain compatibility:

https://www.w3.org/TR/html5/scripting-1.html#attr-script-type

The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a Valid MIME type. The charset Parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".

That is, if not, the default is "text/javascript"

Here’s a related question: You really need to put "text/javascript" in the tag ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.