What are the types of tags involved in javascript?


Html <script> tag

a) The <script> tag is used to define a client-side script.

b) The <script> tag  contains scripting statements or an external script file.

JavaScript code must be keep in script tag.Let's see the use of the tag. For suppose declare the variable outside the script tag.

 Live Demo

Example

<html>
<body>
<p id="tag"></p>
var a = 1;
<script>
   var b = 2;
   var c = a + b;
   document.getElementById("tag").innerHTML = c;
</script>
</body>
</html>

Output

var a = 1


For suppose, let the variable be declared inside the script tag.

 Live Demo

Example

<html>
<body>
<p id="tag"></p>
<script>
   var a = 1;
   var b = 2;
   var c = a + b;
   document.getElementById("tag").innerHTML = c;
</script>
</body>
</html>

Output

3

Updated on: 30-Jul-2019

938 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements