Why do you write 'type="text/javascript" in JavaScript?

Asked 2 years ago, Updated 2 years ago, 17 views

I'm a beginner who just started studying JavaScript. You'll find out later, but I'm asking you a question here because I'm curious. I added javascript to html file and wrote the following code as below.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
    </head>
    <body>
        <script type="text/javascript">
            alert("coding everybody");
        </script>
    </body>
</html>

I wonder why you put "type="text/javascript" in the JavaScript part in the middle. You can use alert or Math without having to put it in.

javascript

2022-09-22 22:12

1 Answers

There are comments like this. Source

To declare a JavaScript (?) 
As far as I know, there are three. 
<script type="text/javascript"> 
<script language="javascript"> 
<script> 
Like this. 

I just write and use short <script>. 
Are there three differences? And which of the three is the right expression? 
I think all three of them are working, but do we need to cover them up?

The script declaration matches your browser's preferences. If you have a browser where the contents inside the script are based on vb, you will try to parse the contents inside to vb. The reason why it works even if you don't use it, or if you use it roughly, is that most browsers' script declarations say to parse themselves. When you write explicitly, the correct syntax is at the top.

<script type="text/javascript" language="javascript"> If you think about sub-browser and completeness, you should write it like above, but usually <script type="text/javascript"> is right now, and it's like where you originally written it.

From html 5, the script is written as js by default, so you can use it only as <script>. If not, you should write <script type="text/javascript">. Even for style tags, type="text/css" must be specifiedStarting from 10,000 html 5, writing <style> by default means css.

The developer who created the current standard <script type="text/javascript"> said.K


2022-09-22 22:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.