JavaScript Introduction

Pretty much in any webpage you look, 3 languages are used:

  1. HTML: This is a markup language and we use it to create
    the content and the structure of a webpage.

  2. CSS: This is a stylistic language and we use it to work on
    the layout and the style of a web page. So the façade of a webpage is
    mainly the art of the CSS.

  3. JavaScript: This is a programming language and is used to set the
    behavior of a webpage.

For example we click on a menu or an icon and a sub-menu or a form appears or a new set of information loads in the page without refreshing the entire page. Or with the help of JavaScript we can track the position of mouse, where the user clicks and essentially store how the users interact with our webpage. Designing and allowing these kinds of interactions with a webpage is the work of JavaScript.

Actually the capabilities of the JavaScript are beyond just a paragraph and this entire tutorial is written to just show you how much you can do with this language. So as we go along, you’ll see the areas in which the language shines.

In your browsers you have this ability to disable JavaScript and not letting websites you are viewing to use it.

Just to see how important JavaScript is for websites, let’s disable it and browse a few websites:

For this example, I’m going to use the Chrome browser:

First go ahead and in the link below, install the Web Developer extension for the Chrome browser:

https://chrome.google.com/webstore/detail/web-developer/bfbameneiokkgbdmiekhjnmfkcnldhhm

After the extension has been installed, go to the Disable tab and disable the JavaScript just like in the picture below:

G:hackjavascriptmy-javascript-tutorial-article-based�-0-JavaScript IntroductionUntitled.png

Now go ahead and open your favorite websites.

For example, go and open the www.twitter.com or www.youtube.com and try to interact with these websites. As you can see, they will start to complain and fail to work properly.

What we did here is essentially disabling their behavior! In a simple word, we crippled websites!

Go and open other websites like Google Drive or www.amazon.com or www.yahoo.com etc. You probably won’t see any change in the style and the façade of those websites. But the moment you start interacting with them (sign in, search, submit form etc.), you’ll see and feel how the lack of JavaScript can stop you from progressing.

Note: some of these websites like Gmail service go even further and stop you right away even before the webpage open up and complain about the JavaScript being disabled and ask you enable it to be able to work with their services.

For many years, the only place that we could run JavaScript programs was within the browsers. Basically if you didn’t have a browser like Chrome, Firefox, Edge etc. there was no way for you to run your JavaScript program. You needed to create an HTML file, and put your JavaScript into that file and open the file in the browser and the execution is done automatically by the browser.

Note: in the quick example section we will show you how to write down a JavaScript program and execute it in the browsers.

But these days we can run a JavaScript program outside of the browsers as well. Basically the JavaScript can also be used in the server-side. For example the Node JS is a runtime environment that enables JavaScript developers to run their code outside of the browsers.

Did You Know?

The name of the JavaScript language wasn’t this when it was initially released at first! In 1995 when the language was released, the first name was LiveScript! But because at the time the Java programming language was one of the hottest programming language, they change the name from LiveScript to JavaScript mainly for marketing strategy.

This is one the reasons that people sometimes confuse the Java and JavaScript languages and think the JavaScript is essentially the spinoff from the Java!

BUT JAVA AND JAVASCRIPT ARE COMPLETELY TWO DIFFERENT AND INDEPENDENT LANGUAGES.

Note: If JavaScript is the first language you’re about to learn and also don’t have any general knowledge about computers, hardware, compilers and other related topics, we highly recommend to first read the articles listed below:

  • Computers in General

  • Software

  • Operating Systems

  • Programming Languages

  • Compilers and Interpreters

  • Linkers

It’s not mandatory to start with these articles but since programming is about writing instructions for computers to run, it’s a good idea to know the environment first!