Programming Languages Section

How To Write Your First Code in JavaScript

javascript programming language blog post
Post by Amina Delali, April 20th, 2020

Some Facts

JavaScript is a lightweight, interpreted, multi-paradigm language . With the language you can write object-oriented code while using at the same time functional and imperative concepts. The specification of the language is defined by the ECMA stantadards. The latest version of the language is ECMAScript 2019 (Standard Ecma-262).

Even if the language was firstly used in web applications, now it is defined as a general purpose programming due to the availability of other environments that embed the JavaScript engine ( the program that executes the JavaScript code).



How to install it

As I said before, JavaScript was firstly and mostly used in web browsers. So, by default, your browser is able to run JavaScript code. In other words, you don't have to install anything.

This being said, if you want to use JavaScript for other purposes. For example, to create desktop applications, you may have to download and install Electron, a framework that will enable you to create those applications.

Sometimes, your browser will disable JavaScript by default. So you can enable it, by following some steps, related to a corresponding browser. As it is explained in this tutorial, that describes ho to enable JavaScript in Internet Explorer.

You can write your code with any editor, and save it with a .js extension. Or you can download a specific tool or plugin to ease your writing. In this video, you will see how to configure Eclipse for JavaScript.

The Hello World Example

For the Hello World Example, I will consider only the case where JavaScript is run by the browser. I will consider these three scnearios :

  • The first one is that the "Hello World!" message will be printed on the console associated with your browser ( the code in the video below is tested on chrome and Firefox consoles).

  • The second one, the message will be printed in a pop up window.
  • In the third one, the message will be printed in a web page.

For the first and second cases, you can run directly your code from the console. I will show you how to do this in the video below.

For the third case, I will use an html file for the web page. So, you can write your code in that same file (hello.html), or in a separate one (hello.js). Of course, I will explain it in the same video below.



Something to say ?

If you want to add something about the Javascrip language or about this post, please feel free to do it by commenting below 🙂 .