Introduction to JavaScript

Introduction to JavaScript

In this article, I am going to give you a brief introduction to JavaScript. As this is the first part of the JavaScript Article series, here we are going to discuss the following pointers in detail which you may have forgotten already or you may not be aware of (beginner).

  1. History of JavaScript
  2. How JavaScript was designed?
  3. What is JavaScript?
  4. What JavaScript Can do For us?
  5. Understanding ECMAScript.
  6. How does JavaScript Engine work?
  7. What makes JavaScript unique?
  8. What is Validation?
  9. Why do we need both client-side and server-side validation?
  10. Advantages and Disadvantages of using JavaScript.
  11. What software can be used for JavaScript programming?
  12. What should we know before learning JavaScript?
History of JavaScript:

How much do you know about the history of the most popular programming language?

History of JavaScript

Timeline History:

1995 JavaScript was born and was created by Brendan Eich, a Netscape Communications Corporation programmer. Brendan Eich took only 10 days to develop the Scripting language which was then known as Mocha. The scripting language name was changed from Mona (and LiveScript) to JavaScript.

JavaScript’s original name was Mocha. JavaScript has nothing to do with Java. Java was famous in that era, hence the name “JavaScript” was chosen to ride on Java’s success. Microsoft created a reverse-engineered version of JavaScript, known as JScript.

1996 JavaScript is handed to ECMA. The Scripting language was given the name “ECMAScript” officially; however, people still call it JavaScript. In 1996-1997 JavaScript was taken to ECMA carve out standard specifications. ECMAScript is the name of the official standard, with JavaScript being the most well-known of the implementation, other implementation includes ActionScript3.

1998 ECMAScript 2 is released.

1999 ECMAScript 3(baseline for modern-day JavaScript) is released. This released evolved into what is today’s modern JavaScript.

ECMAScript5 was released in December 2009.

The JavaScript community flourishes. The community’s impact peaked with a paper released in 2005 by Jesse James Garret describing a set of technologies that JavaScript supported as a backbone and where he created the term ‘Ajax’. Additionally in 2005, jQuery, Prototype and Dojo were released.

ECMAScript 4 never happened.

We are at ECMAScript 6 (Officially: ECMAScript 2015), also known as ES6.

92% of all websites use JavaScript including some of the world’s biggest websites such as Google and Facebook.

How JavaScript was designed?

In 1995 Netscape made the best browser in the world and have received market dominance.so they thought the browser/server combination as a new kind of distributed operating system. Browsers had the potential to let developers reach users on any platform such as Windows, Mac, or Linux .but the missing contents were a programming language. What Netscape wanted was a language to complement Java that would appeal to beginning programmers.

Netscape hired Eich in 1995 because they wanted him to create a programming language for that web browser.

JavaScript evolve and started as Mocha, then became LiveScript and then became JavaScript when Netscape and Sun got together. They did a license agreement and it became Javascript.

They aimed to provide a “glue language” for the Web designers and programmers who were building Web content from components such as images, plugins, and Java applets. They found Java as the “component language” used by higher-priced programmers, where the glue programmers – the Web page designers – would assemble components and automate their interactions using JS.

JavaScript was specifically developed to be a language place into a web browser and automate things on the client-side, such as, animating drop-down menus, validate form input before submitting to the server or manipulate the document object model (DOM). In the beginning, that was all it was meant to do.

Then came AJAX (Asynchronous JavaScript and XML). AJAX-enabled the browser to talk directly to an executable on the server, fetch data and populate the DOM so that new content could be pumped in/removed from the page. This made JavaScript an essential component of the browser.

Then came Google’s Version 8 JavaScript engine and node.js and it really became a lot more interesting. This made easy to write server-side code in JavaScript.

JavaScript is the only language that runs both on the server and the browser. Firefox OS has all apps written JavaScript. We can write JavaScript apps for Android and iOS.

With the rise of WWW and the internet both, JavaScript became the most popular programming language in the world. Today we even create frameworks and implement animations using JavaScript.

What is JavaScript?

JavaScript is one of the most popular and used programming languages in the world. It is a lightweight, interpreted, open and cross-platform programming language.

JavaScript is completed object-based scripting language produced by Netscape for use within HTML documents and enables interactions with web pages in various unique ways.

JavaScript became an independent language with its own specification called ECMAScript, it is an implementation of ECMAScript standard.

What JavaScript Can do For us?

JavaScript is basically used to make the web pages dynamic, interactive, and also add special effects on a page such as a rollover, rollout and many graphics. such as

    • used to insert dynamic text into the HTML (ex: Name, Address, etc.)
    • react to events (for example, load the page only when the user click on a button)
    • JavaScript also used to fetch the information of the user’s computer such as which browser the user using.
    • It also used to perform some calculations on the user’s machine such as validating the user input.
    • Animated/dynamic drop-down menus
    • Displaying clock, date and time.
    • Get and set cookies, ask questions to the visitor, show messages.
    • Remember the data/info on the client-side (“local storage”).

JavaScript is a CS (Client-Side) scripting language. It is in no way related to Java as its name implies, but it is used for client-side scripting.

Client-Side scripting, means the ability to manipulate data, the DOM and a webpage as a whole, without having a backend service or language.

We can make calculations, validate a form or any input field, include some logic that runs when a condition is met, also can manipulate the webpage and add a lot of function to a website without any SS (Server-Side) language.

On the introduction of frameworks like Node.js, JavaScript started using server-side technology. The Node.js changed the way JavaScript was used. It allows the use of JavaScript on the server-side while APIs, which lead the MEAN way for developing software where secured, database connected app could be written using JavaScript.

With the new development, not only web-based applications can be developed using JavaScript, even desktop-based (Electron), hybrid mobile app (Ionic), the real-time app can be developed as well.

It’s the only language used on the client-side which is supported by all browsers. The complete JavaScript implementations are made up of three distinct parts:

  1. The Core(ECMAScript)
  2. The Document Object Model(DOM)
  3. The Browser Object Model(BOM)

JavaScript

ECMAScript:

 

ECMAScript

ECMAScript is simply a description, defining all the properties, methods and objects of scripting language.

  1. Syntax
  2. Data Types
  3. Statements
  4. Keywords
  5. Reserved Words
  6. Operators
  7. objects

Each browser has its own implementation of the ECMAScript interface, which is then extended to contain the DOM and BOM. Today, all popular web browsers comply with the 3rd edition of ECMA.

  1. DOM (we will discuss later)
  2. BOM (we will discuss later)

JavaScript is easy to learn but very powerful just because the entire Internet can’t run without it. The entire web site will become static without it. In Today’s world, there are so many JavaScript libraries or frameworks available. Some of them are listed below.

  1. NodeJS
  2. AngularJS
  3. ReactJS
  4. VueJS
  5. EmberJS
  6. MeteorJS
  7. BackboneJS
  8. ExpressJS
  9. WebRxJS
  10. jQuery

The Programs written in JavaScript language are called scripts. They can be written directly in web page HTML and run as the page loads.
Scripts are executed as plain text and don’t need any compilation to run. Today JavaScript can run not only in the browser but also on a server or any other device that has a special program called the JavaScript Engine.
The browser has an embedded engine called “JavaScript Virtual Machine”. The different browser has a different engine. And different engines have different “codenames”. For example:

  1. V8 – in Chrome and Opera.
  2. SpiderMonkey – in Firefox.
  3. “Chakra” for IE, “ChakraCore” for Microsoft Edge, etc.
How does JavaScript Engine work?

The Engine works once we write JavaScript code.

  1. The JavaScript Engine (parses) read the source code (script).
  2. Then its compiles (convert) the JavaScript code into machine language at the execution by implementing Just-in-Time (JIT) compiler.
  3. And then the machine code runs.

The JavaScript engine applies optimizations at each step of the process. It watches the compiled script as it runs, analyses the data that flows through it, and further optimizes the machine code based on that knowledge.

What makes JavaScript unique?

JavaScript is the only browser language that combines below three things and that’s what makes it unique.

  1. JavaScript is fully integrated with HTML/CSS.
  2. Simple’s things are done easily.
  3. It’s supported by all the browsers and enabled by default.
What is Validation?

It’s a process of testing and ensuring that data inserted by the user into an application are required and satisfies defined formats and other input criteria.so that only valid data can be submitted to a web application by end-user.

Why do we need both client-side and server-side validation?

Validation can be performed either on the server-side or client-side (user browser).

Client-side Validation:
  1. In client-side validation, all the input data validation and error recovery are carried out by on client-side i.e. user browser using JavaScript.
  2. It works fast and easier for the end-user.
  3. It is generally insecure as the user has easy access to the code of the page.
  4. It is used to reduce the errors that might come during server-side processing.

Pros:

  1. It works very fast
  2. It minimizes the errors

Cons:

  1. It has low security

For Example: If a user enters an invalid email address and move to the next field, we can show the error message immediate right after, so that the user can correct the field before submitting the form. Whereas if we validate the same on the server, we have to submit the form to the server, the error message gets to display and then we can correct the wrongly entered the field.

Server-side Validation:

In server-side validation, all the input data validation and error recovery are carried out by on the server-side i.e. user browser using programming language like C#.net, Java, etc.

  1. It works comparatively slower for the user.
  2. It is more secure as the end-user does not have easy access to the code.
  3. It is used to rescue any type of damage which can come during client-side validation.

Pros:

  1. It has high security

Cons:

  1. It is slow in execution. As every time request will be sent to the server for validation.

Note: Both types of validations play important roles but the most preferred one is the server-side is that the client-side validation can be bypassed/modify if JavaScript is turned off (disable) in the user browser.in this client-side validation won’t work hence it becomes useless. That is why we need a server-side to check the data value as well.

But we need to do both as client-side give immediate validation response to user input without having to wait for the page to load. Whereas the server-side will always capture the validations which are not caught by the client-side validation.

*Try to always validate on the server.*

Advantages and Disadvantages of using JavaScript:
Advantages:
  • Runs Fast: The JavaScript code runs without contacting the server.
  • Platform Independent.
  • Easy to Learn.
  • Increased interactivity: we can create an interface that reacts when the user interacts like hovering them with a mouse.
  • Less Server Interaction: we can validate the user input before submitting the page to the server. This saves server traffic that means less load on the server.
  • Immediate feedback to the user: we don’t have to wait for a page to load to check if any wrong data got entered.
  • Rich Interface: Using JavaScript we can build rich user interfaces such as drag-and-drop components and sliders.
Disadvantages:

We can’t consider JavaScript as a full-fledged programming language as it has lacked in feature such as:

  • Run-on Single thread: JavaScript doesn’t have multithreaded and multi-process capabilities.
  • Read/Write Files: JavaScript doesn’t allow reading or writing files due to security concerns.
  • Networking Application: We cannot use JavaScript for networking related applications.
  • Code is not hidden: Even we can minify JavaScript code, the code is always visible to Client end
What software can be used for JavaScript programming?

As we know JavaScript is client-side scripting that runs by web browsers. To write a program in this language we can use the following software’s:

  • Chrome as a web browser + browser console to debug.
  • Any text editor like Notepad /Notepad++

OR

  • Visual studio
What should you know before learning JavaScript?

You should have some or little knowledge of HTML before learning JavaScript. A JavaScript program can be typed in the head section or in the body section of the HTML page or it could be attached externally to the web pages.

That’s it for today. In the next article, I am going to discuss how to write JavaScript Program in detail. In this article, I try to give a brief introduction to JavaScript and I hope you enjoy this article.  

Leave a Reply

Your email address will not be published. Required fields are marked *