JavaScript Introduction

JavaScript Introduction

JavaScript is the most commonly used client-side programming language. All modern HTML pages used JavaScript to add more functioning, better user experience and more interactive.


With the help of JavaScript you can do anything in client side like change the HTML content, change the style of elements etc.


You can use javascript internally or externally.

Syntax of Internal JavaScript

JavaScript can be placed in the <head> section of the HTML page. And the JavaScript code must be inserted in the <script> and </script> tags


Example of JavaScript

<html>
<head>

<script>
document.write("Hello This is the Example of JavaScript");
</script>

</head>
<body>

<p>This is paragraph 1 </p>
<p>This is paragraph 2 </p>
<p>This is paragraph 3 </p>
<p>This is paragraph 4 </p>

</body>
</html>



Syntax of External JavaScript

You can use JavaScript by defining all your code in a seperate file and save the file with .js extension and then add that file in your webpage


Example of External JavaScript

/*This is demo.js file*/
document.write("Hello This is the Example of JavaScript");

<!--This is samplejs.html file-->
<html>
<script src="demo.js"></script>
<body>

<p>This is paragraph 1 </p>
<p>This is paragraph 2 </p>
<p>This is paragraph 3 </p>
<p>This is paragraph 4 </p>

</body>
</html>

You can place the external javascript file un the head tag or in body.




JavaScript Single and Multiline Comments

Comments is used to easily read the codes, comments cannot be executed and cannot be read by the users.


//This is single line Comment

/*
This is a 
Multiple line Comment
*/
Next

Join Us And Get Our Latest Tutorials Updates Via Email