JavaScript is the most popular programming language in the world. Java and JavaScript are completely different languages, both in concept and design. The official name for JavaScript is actually ECMAScript.

 

What is JavaScript?

JavaScript is one of the 3 languages all web developers must learn:

  1. HTML to define the content of web pages
  2. CSS to specify the layout of web pages
  3. JavaScript to program the behavior of web pages

This tutorial is about JavaScript, and how JavaScript works with HTML and CSS.

 

This is an example for JavaScript first program:

<script>
   var greeting = "Hello, World!"; //create a variable
   document.write(greeting); //print the variable
</script>

 

In the example we can spot a variable declaration. It is done using var keyword followed by assignment “=” operator and a string literal enclosed in double quotes. The variable type is therefore a string.

 

JavaScript in Browser

JavaScript is working in a browser (Chrome, Firefox) and is handling a document. It does not have it’s own user interface but is embeded into an HTML page. Therefore we reffer to document object to write something into it.

 

JavaScript in Node

JavaScript can be run outside of web browser using Node.js virtual machine.

Node JS Home

Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

 

Using Node we can create:

  • console based applications
  • back-end web server applications

Node has included inside an HTML server that can be used to render and serve HTML pages.