javascript syntax

No comments
                                JavaScript Syntax

JavaScript can be implemented using javascript statements that are placed between the <script>.....</script> HTML tags in a webpage. Javascript statements are separated by semicolons.

 A simple syntax of JavaScript code appears as follows:
<script ....>
 Javascript code
</script>
The script tag takes two important attributes.

language: This attribute specifies what scripting language we use.
type: This attribute is what is now recommended to indicate the scripting language in use and its value should be set to "text/javascript".

<html>
<body>
<script language="javascript" type="text/javascript">
<!--
 document.write("Hi")
//-->
</script>
</body>
</html>

Example-2:

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Statements</h1>
<p>Statements are separated by semicolons.</p>
<p>The variables x, y, and z are assigned the values 5, 6, and 11:</p>
<p id="demo"></p>
<script>
var x = 5;
var y = 6;
var z = x + y;
document.getElementById("demo").innerHTML = z;
</script>

</body>
</html>


No comments :

Post a Comment

Related Posts Plugin for WordPress, Blogger...