loader image

JavaScript-Introduction

JavaScript, often abbreviated as JS, is a programming language that conforms to the ECMAScript specification. JavaScript is high-level, often just-in-time compiled, and multi-paradigm. It has curly-bracket syntax, dynamic typing, prototype-based object-orientation, and first-class functions. 

Let's

INTRODUCTION

What is JavaScript?

Javascript is a High Level, Object Oriented, Multi Paradigm Programming Language.


JavaScript was initially created to “make web pages alive”.

The programs in this language are called scripts. They can be written right in a web page’s HTML and run automatically as the page loads.

Scripts are provided and executed as plain text. They don’t need special preparation or compilation to run.

JavaScript is very different from another language called Java, but was named Javascript because at the time(in 1995) Java was a very popular language

Today JavaScript is an independent language ECMAScript, and now it has no relation to Java at all.

JavaScript can execute not only in the browser, but also on the server, or actually on any device that has a special program called the JavaScript engine.

The browser has an embedded engine sometimes called a “JavaScript virtual machine”.

Different engines have different “codenames”. For example:

  • V8 – in Chrome and Opera.
  • SpiderMonkey – in Firefox.
  • There are other codenames like “Chakra” for IE, “ChakraCore” for Microsoft Edge, “Nitro” and “SquirrelFish” for Safari, etc.

 

What Does an Javascript Engine do?

  1. The engine (embedded if it’s a browser) reads (“parses”) the script.
  2. Then it converts (“compiles”) the script to the machine language.
  3. And then the machine code runs, pretty fast.


In-browser JavaScript capabilities

  1. Add new HTML to the page, change the existing content, modify styles.
  2. React to user actions, run on mouse clicks, pointer movements, key presses.
  3. Send requests over the network to remote servers, download and upload files (so-called AJAX and COMET technologies).
  4. Get and set cookies, ask questions to the visitor, show messages.
  5. Remember the data on the client-side (“local storage”).

What Javascript Can’t Do:

  1. JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to OS functions.
  2. Same Origin Policy- Different tabs/windows generally do not know about each other. Sometimes they do, for example when one window uses JavaScript to open the other one. But even in this case, JavaScript from one page may not access the other if they come from different sites
  3. JavaScript can easily communicate over the net to the server where the current page came from. But its ability to receive data from other sites/domains is crippled. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that’s a safety limitation.

Figure to describe Javascripts capabilities


Such limits do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow plugin/extensions which may ask for extended permissions.

What makes JavaScript unique?

  • Full integration with HTML/CSS.
  • Keeps it simple
  • Support by all major browsers and enabled by default.

 

Summary

  • JavaScript was initially created as a browser-only language, but it is now used in many other environments as well.
  • Today, JavaScript has a unique position as the most widely-adopted browser language with full integration in HTML/CSS.
  • There are many languages that get “transpiled” to JavaScript and provide certain features. It is recommended to take a look at them, at least briefly, after mastering JavaScript.
error: Content is protected !!