Javascript is a computer programming language used mainly for web development purposes. It was created by the Netscape browser in 1995, and it was a way for them to add action to their website. JS could be considered as a verb. That is, it enables actions like playing YouTube videos, signing up for a username, tweeting, posting, etc. It is lightweight and dynamic with object-oriented capabilities. Without Javascript on the web, we would have just HTML and CSS, making the web pages static, and only dynamic changes like animations from CSS will be left.
Now that we know what Javascript is all about in a nutshell, let us look at what you can do with it. It is applicable in the following ways:
It is mainly used in the addition of interactive behaviour to web pages. Examples of such interactions could be the changing of the font color or button color when the mouse hovers over it, playing a video on a web page, displaying a timer on a site, and so on. There are many other things you can do with respect to this.
Various Javascript frameworks (Collections of Javascript code libraries that provide pre-written code) can be used in the creation of web and mobile apps. Some examples of Javascript frameworks are: React, React Native, Angular, and Vue for frontend. A very solid example of a platform that uses JS is Instagram.
Javascript can also be used in the building of web servers and development of server applications. Do you love games? Here’s one fun fact. You can use Javascript to create browser games.
You will get to know more about Javascript as we proceed with our lessons, but before that, let us see how we can add javascript to a web page.
There are two methods of adding JavaScript to a webpage;
- The first is by adding a script tag and typing the code within it.
- And the second method is by adding an external Javascript code to the webpage.
For the first method, we will be embedding our javascript in the HTML code. To do that, type the following code in any code editor of your choice and save the file with the extension “.html”. After saving, you open the saved file (HTML file).
index.html
The above code produces the following output.
OUTPUT
The second method is by adding an external javascript code to the webpage. It can be done by typing the javascript code in any code editor of your choice and saving the file with the “.js” file extension. After creating it, you then open your html code and you add the directory link to where the javascript file is saved on your computer. Let’s try to reproduce the above by using this second method.
Modify your HTML code at the level of the script tag to be like the one below.
According to the code above, our Javascript file name is script.js .Below is the code found in the JS file.
script.js
Observe the output of the second method :
Now we have come to the end of this lesson. I hope you learned something new today? Please subscribe to our youtube channel for more exciting tutorials. In the next lesson, we will be looking at Javascript variables. Thanks for your attention.
Comments
Post a Comment
Please do not enter any spam link in the comment box.