Javascript Introduction


JavaScript is a cross-platform, light-weight, interpreted scripting language that allows us to create interactive web pages and web applications. It is a high level, compiled and interpreted, multi-paradigm language that supports event driven and functional programming styles. According to a recent survey by Stackoverflow, JavaScript is the most popular language on Earth.

JavaScript offers several advantages to a web developer such as a short development cycle, small size scripts and so on. The strengths of JavaScript can be easily and quickly used to extend the functionality of HTML pages already on the website.

JavaScript is case sensitive and we use it inside HTML using <script> tag.
The basic syntax used in Javascript code is:



<script type="text/javascript">
//Javascript Code goes here
</script>



Combining it with HTML code, it looks like:



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
</head>
<body>
<h1 id="our-heading"> Hello World </h1>

<!--All JavaScript Code goes within the script tags -->
<script>
document.getElementById("our-heading").innerHTML = "New Text";
</script>

</body>
</html>

Live Demo!

Output


New Text

The Script Tag

<script></script>

All the javaScript code must go inside the script tag. Script tag can be added before the closing body tag.




Try it yourself

Assign an ID to the heading, and change the text of h1 tag using JavaScript.


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
</head>
<body>

<h1> Hello World </h1>

<!--All JavaScript Code goes within the script tags -->
<script>
// Your Code will go here
</script>

</body>
</html>

Live Demo!