JavaScript at a Glance – An Introduction

Welcome to the series “JavaScript at a Glance”, where we will embark on a journey to explore JavaScript, so come with me as I introduce you to this awesome and versatile programming language.

The Birth

JavaScript was created by Brendan Eich just 10 days back in 1995 while he was working at Netscape Communications. At the beginning, it was called “LiveScript”, but later, it was renamed “JavaScript’.

What is JavaScript?

JavaScript is a high-level programming language primarily known for its use in web development. It is an essential component of modern web applications.

Let us take a quick look at what JavaScript really is, what it can do and how to use it. Quickly, open a chrome browser, click the three dots at the uppermost right hand side to go to the menu, select more tools and then developer tools.

I am glad you are able to locate it, next click on the console. The console allows you to start writing JavaScript straight away and it will run it once you click enter. Take a look at an example below:

If you hit enter, chrome will run this line of code and bring a popup saying “Hello World”. Press Okay and the popup will disappear.

Using the chrome browser console is awesome, if you want to run multiple lines of code hold down shift and press enter (shit + enter) .

If you hit enter, it will first execute the first popup which says “Hello” and then if you click okay it will execute the second popup that says “World”.

READ ALSO: FIRST DAY WITH HTML

Another way of writing JavaScript code that can be executed inside the console is to go to “Sources”, and on the left corner you will see two little arrows pointing towards the right, click on it and go to “Snippets”. This is a hidden area in the chrome browser and a lot of people don’t know about it, but it is really useful for what we are trying to do.

Once you are there, create a new Snippet, by clicking on “+ New Snippet” and give your script a name with an extension of “.js” as shown in the image above. After creating it, when you select it, you will see an area on the right hand side where you can start writing your JavaScript code. With this, you can write as many lines of code as you wish and once you are done, you can proceed to the bottom and click run or (ctrl + Enter) to execute the code.

Next, we will take a deeper look into this code we have been writing “alert(“Hello”). The alert in this case is a keyword and keywords are special, you can’t just use any word out of the box. It will throw an error. It has to be something that the browser knows about. The browser knows that when you type alert(), you are trying to tell it to create a popup.

This alert() keyword is called a function. The reason is because it is a little bit of functionality, it gets the browser to do something. The middle part is the message. This is what we want the browser to show in the popup. It does not matter what you write there, for whatever you put there, that is what the browser will display in the popup. Notice that at the end, there is a semicolon which denotes the end of the instruction, the end of the command or statement. This is done so that the browser doesn’t get confused by adding one line of code to another line.

Finally, you now know what JavaScript is, you have written your first code in JavaScript, kudos to you!!! In the next series we will look into “Data Types, explore the various types and how to use them. Whether you are a newcomer to programming or already in the journey looking to expand your skill sets, join us as we journey through the world of JavaScript together one step at a time. There will be tasks and projects along the way as we proceed, so stay tuned. Remember, practice is the key. If you have any questions leave it in the comment below. Shallout!!!