GNU/Linux Programmer's Solver - JavaScript

Hello World program in JavaScript. Basic structure, comments and string literals
PROGRAMMING JAVASCRIPT ECMASCRIPT HELLO WORLD
#!/usr/bin/nodejs

// This is a comment in one line
/* This is a multiline
   comment */
console.log ("Hello World!!");
// As per  ES6
console.log (`This is a message
using several text lines
in JavaScript`);

JavaScript is the language used by Browsers to execute code on the client side, that is, in the browser itself. It is an interpreted language (in most cases), and the interpreter is usually integrated into the browser. The release of node.js allowed this language to be used to develop complete applications and not just add interactivity to web pages.

JavaScript programs usually use the .js extension.

JavaScript has a syntax very similar to that of C or Java, including the way comments are added to the program with the characters // or /* ... */. As we have seen in other languages, backticks can be used to define multi-line strings.

The way to print messages varies depending on the environment in which your program is running, but the use of the console is usually available in all cases. When we use JavaScript in the browser, we normally use the web page to display the results of our program.

Aside from the fact that JavaScript normally uses the HTML page on which it runs to display information (in which case carriage returns are irrelevant and HTML tags indicate whether there is a carriage return or not), console.log prints each of the strings it receives on a line, since it was originally conceived as a debugging function.

DID YOU KNOW

The standardization body ECMA defined the so-called ECMAScript to try to define a standard version of JavaScript. ECMAScript covers more languages than JavaScript and it is normally used this term when we talk about server applications or services using node.js

There are different versions of JavaScript normally known as ESX where X is an integer. Each version adds new functionalities to the language. For example, in the code of this section, we can see how to use backticks to define a multi-line string… This capability is only available from version 6 of the language (ES6).

To execute the program, you can install node.js or include it in a web page and run it in the browser… although, the latter option is probably more cumbersome.

In any case, the code is shown below. You just have to open this page in a browser and access the JavaScript console. The way to do the latter will depend on the browser you use.

<html>
  <body>
    <script>
      console.log ("Hello World!\n");
    </script>
  </body>
</html>

The origin of JavaScript is closely linked to the development of the web and browsers. Back then (mid-nineties), while it was possible to generate pages dynamically using technologies like CGI (Common Gateway Interface), once the page was loaded in the browser, there wasn’t much to do. Netscape Navigator was the most used browser, and in 1995, the company decided to add a scripting language to the browser to be able to give dynamic capabilities to pages on the client side, to which it followed two paths… Integrating the newly released Java language by Sun Microsystems, or integrating an interpreter of Scheme (something like a reduced version of Lisp easy to integrate in other programs). In the end, Java became popular, and scheme/lisp never did, so Netscape finally developed a new language with a syntax similar to that of Java.

That initial language was called LiveScript, but in a few months it was renamed as JavaScript. It is said that the name was changed to capitalize on the pull of Java and in truth for a while people thought it was the same language or an interpreted variant of Java.

Netscape was the undisputed leader as a web browser for some time. Microsoft Explorer gained popularity thanks to strategies that years later would end up being condemned in court. In any case, the browser war had begun. It was a tough time for developers, because both Netscape and MS Explorer added their unique and peculiar features that effectively made pages designed for one not display correctly on the other. Microsoft’s version of JavaScript was called JScript.

I’M YOUNG

While Netscape and Explorer were the protagonists of the browser war, in the early days of the web, there was another browser called Mosaic. More specifically NCSA Mosaic, since it was developed by the National Center for SuperComputing Application belonging to the University of Illinois. NCSA Mosaic was the first graphical browser for navigating the web and its initial version was for UNIX systems over X-Windows.

From there, Microsoft Explorer became the undisputed leader and JScript and its peculiarities the de facto standard. This would last until Mozilla launched Firefox in 2004. Mozilla actively participated in the standardization process through ECMA (European Computer Manufacturers Association) International and, hand in hand with Macromedia (the creators of Flash, now part of Adobe), developed the standard ECMAScript for XML (E4X). Macromedia was implementing E4X in its ActionScript 3 language and the idea was that ActionScript 3 would be standardized as ECMAScript 4. Adobe launched Tamarin, a virtual machine with JIT capabilities whose intention was to be used to execute ES4. Tamarin was part of the infrastructure for executing Flash and the intention was to unify the languages on the client side. However, ES4 and ActionScript3 were so different that this initiative did not take off.

In 2005, Jesse James Garret, introduced the concept of AJAX as a series of technologies based on JavaScript to allow the loading of data in the background in web applications… It was this technology that gave JavaScript the final push to achieve the popularity it has today.

A few years later, in 2008, Google released Chrome with a novel JavaScript engine with JIT capabilities called V8, which notably improved the performance of JavaScript code, which for some time made the poor internauts suffer.

I’M A NEWBIE

JIT stands for Just-In-Time, a term that is usually associated with compilers that work dynamically, which are used in interpreted languages to improve performance. The JIT compiler does what it does by compiling the interpreted program (or parts of it) to native machine code, so that its execution speed is drastically reduced.

Since the compilation process requires a certain time, these engines with JIT capabilities normally do not compile all the interpreted code, but either do so incrementally as they need it or, the most sophisticated, detect which parts of the program need to be executed faster and those are the ones they compile. Those parts are called Hot Spots or hot points.

At the end of 2009, the ECMAScript5 (ES5) standard was published, the first one in which they tried to combine all the important features of the language and take it to the next level. This was, let’s say, the first unified version of the language.

JavaScript (or ECMAScript more correctly) continued to develop and ECMAScript 6 saw the light in 2015. And from that moment on, annual revisions of the standard have been published. At the time of writing this text, ES11 is the latest defined version, however, only Firefox supports versions superior to ES7. The version.

DID YOU KNOW…

ES.Next is a special name used to refer to the next version of the language…

Summary

  • Interpreted language
  • Extension: js
  • Line terminator: ;
  • Groups instructions with: { instructions }
  • Multiline comments: /* comment */
  • Same line comments: //
  • String delimiter: "string"
  • You can print texts with console.log (Adds carriage return)
  • Support multiline strings: `multiline string`
  • Does not support HERE-DOCS
  • Entry point: Function main

Related Posts

GNU/Linux Programmer's Solver
Chapter 1 - Hello World

Hello World is the first program you write when learning a new language and there are good reasons for that

Read

PROGRAMMING HELLO WORLD

GNU/Linux Programmer's Solver - PHP

Hello World program in PHP. Basic structure, comments and string literals

Read

PROGRAMMING PHP HELLO WORLD

GNU/Linux Programmer's Solver - ADA

Hello World program in ADA. Basic structure, comments and string literals

Read

PROGRAMMING ADA HELLO WORLD

Return to Home Page