I have seen many different ways in declaring script tag. Some of them are:
Variation 1:
<script type="text/javascript">
//some javascript here
</script>
Variation 2:
<script type="text/javascript">
//<![CDATA[
// some javascript here
//]]>
</script>
Variation 3:
<script language="javascript">
//some javascript here
</script>
Variation 4:
<script>
//some javascript here
</script>
There are also other variations as well. When we work in HTML5 + js then which way is more appropriate in declaring Script tag?
Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.
Definition and UsageThe <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
<script>: The Script element. The <script> HTML element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code.
The script tag should always be used before the body close or at the bottom in HTML file. The Page will load with HTML and CSS and later JavaScript will load.
In HTML5 you don't need an additional attribute like "type". Just declare JavaScript code with <script></script>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With