JAVASCRIPT - BASIC
What is JavaScript?
JavaScript is a programming language of web. It is quite lightweight and executes in the browsers of the webpage.
Often you have seen popup window appearing once you click a button in a webpage. That is JavaScript in the background, which is making the popup appear.
Why should you learn JavaScript?
-
Most popular language
JavaScript is the most popular language now.
-
Easy to learn
JavaScript code is quite easy to write due to its simple syntax.
-
Base of the Programming language in web
If you are working on frontend frameworks like Node JS or JQuery, JavaScript is the base of those frameworks.
First JavaScript Application
Let us write our first JavaScript Application which just prints Hello World on the screen.
Example :
<html>
<body>
<script language = "javascript" type = "text/javascript">
document.write("Hello World")
</script>
</body>
</html>
Output :
Hello World
-
In the above code we are printing Hello World using the below statement :
document.write("Hello World")
We do not have to dig much into individual component in the output statement for now. We can just remember, document.write() is the statement used to print something on the screen.
-
Since, JavaScript is the language of web. All JavaScript programmes should be written inside and tags,
<html>
<body>
....
....
</body>
</html>
-
Inside the <html> and <body> tags, there is a <script> tag. And that specifies that the language we are going to use is JavaScript. The <script> tag is the entry point of a JavaScript application. So, JavaScript executes the code written inside the <script> tag :
<script language = "javascript" type = "text/javascript">
document.write("Hello World")
</script>
Since, document.write("Hello World") is inside the <script> tag, it got printed.
Moral of the Story
We have to write all our codes inside the <script> tag. And the <script> tag should be inside <html> and <body> tags.
<html>
<body>
<script language = "javascript" type = "text/javascript">
document.write("Hello World")
</script>
</body>
</html>