Introduction

JavaScript is a cross-platform, object-oriented scripting language. It is a small and lightweight language. Inside a host environment (for example, a web browser), JavaScript can be connected to the objects of its environment to provide programmatic control over them.

It is used to make web pages alive. It is used to programmatically perform actions within the page. When JavaScript was created, it was initially called "LiveScript". But Java was a very popular language at that time, so it was decided that positioning a language as a "younger brother" of Java would help.

JavaScript contains a standard library of objects, such as Array, Date, and Math, and a core set of language elements such as operators, control structures, and statements. Core JavaScript can be extended for a variety of purposes by supplementing it with additional objects; for example:

  • Client-side JavaScript extends the core language by supplying objects to control a browser and its Document Object Model (DOM). For example, client-side extensions allow an application to place elements on an HTML form and respond to user events such as mouse clicks, form input, and page navigation.
  • Server-side JavaScript extends the core language by supplying objects relevant to running JavaScript on a server. For example, server-side extensions allow an application to communicate with a database, provide continuity of information from one invocation to another of the application, or perform file manipulations on a server.

JavaScript (JS) is a lightweight interpreted (or just-in-time compiled) programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js, Apache CouchDB and Adobe Acrobat. JavaScript is a prototype-based, multi-paradigm, single-threaded, dynamic language, supporting object-oriented, imperative, and declarative (e.g. functional programming) styles.

JavaScript's dynamic capabilities include runtime object construction, variable parameter lists, function variables, dynamic script creation (via eval), object introspection (via for...in and Object utilities), and source-code recovery (JavaScript functions store their source text and can be retrieved through toString()).

HTML, CSS and JS:

They can be defined as
  • HTML: It is the markup language that we use to structure and give meaning to our web content, for example defining paragraphs, headings, and data tables, or embedding images and videos in the page.

  • CSS: It is a language of styles that we use to apply styling to our HTML content, for example setting background colors and fonts, and laying out our content in multiple columns.

  • JS: It is a scripting language that enables us to create dynamically updating content, control multimedia, animate images, and pretty much everything else.

What can JavaScript do?
  • JavaScript can execute not only in the browser, but also on the server.
  • We will use JavaScript as a client as well as server side language.
  • JavaScript has evolved greatly as a language and is now used to perform wide variety of tasks.
What can In-Browser JavaScript do?
  • Add new HTML and change existing HTML from DOM.
  • React to events like response from server, key press, mouse movement, etc.
  • Ajax requests like get, post request from network.
  • Get and Set cookies and use local storage.
What make JavaScript unique?
  • HTML and CSS support.
  • simple things, i.e., simple API
  • supports major modern browsers (enabled by default).
JavaScript versions

JavaScript was invented by Brendan Eich in 1995. It was developed for Netscape 2, and became the ECMA-262 standard in 1997. After Netscape handed JavaScript over to ECMA, the Mozilla foundation continued to develop JavaScript for the Firefox browser. Mozilla's latest version was 1.8.5. (Identical to ES5). Internet Explorer (IE4) was the first browser to support ECMA-262 Edition 1 (ES1).

  • maintained by community
  • First version in 1997
  • Second version in 1998
  • Third version in 1999
  • few releases, and latest version is ECMA 2015. Wherever the talk is about ECMA, it is about JavaScript. ECMA 2016, 17, 18, and every year it changes and you will see newer versions of ES like ES5, ES6.
  • latest version is ECMAScript 2020

Official Documentation

What you should already know

This guide assumes you have the following basic background:

  • A general understanding of the Internet and the World Wide Web (WWW).
  • Good working knowledge of HyperText Markup Language (HTML).
  • Some programming experience. If you are new to programming, try one of the tutorials linked on the main page about JavaScript.
JavaScript and Java

JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java expression syntax, naming conventions and basic control-flow constructs which was the reason why it was renamed from LiveScript to JavaScript.

In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead of the more common class-based object model. The prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.

JavaScript is a very free-form language compared to Java. You do not have to declare all variables, classes, and methods. You do not have to be concerned with whether methods are public, private, or protected, and you do not have to implement interfaces. Variables, parameters, and function return types are not explicitly typed.

Hello World

To get started with writing JavaScript, open the Scratchpad and write your first "Hello world" JavaScript code:

console.log("Hello world!");

Select the code in the pad and hit Ctrl+R to watch it unfold in your browser!