JavaScript: Use Cases

Prithviraj Singh
14 min readJun 25, 2021

What is JavaScript?

JavaScript is a cross-platform, object-oriented scripting language used to make webpages interactive (e.g., having complex animations, clickable buttons, popup menus, etc.). There are also more advanced server side versions of JavaScript such as Node.js, which allow you to add more functionality to a website than downloading files (such as realtime collaboration between multiple computers). 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.

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.

This means that in the browser, JavaScript can change the way the webpage (DOM) looks. And, likewise, Node.js JavaScript on the server can respond to custom requests from code written in the browser.

JavaScript is a flexible and powerful programming language that is implemented consistently by various web browsers. Along with HTML and CSS, it’s a core component of web technology. While HTML is responsible for structure and CSS is responsible for style, JavaScript provides interactivity to web pages in the browser.

But JavaScript was never meant to become the cornerstone of modern web development. In fact, the language was created in less than two weeks, with a very different purpose in mind.

History of JavaScript

When the Internet boomed with public usage in the 1990s, technology companies battled to build the most powerful and efficient web browser on the market. This sparked the first “browser war,” between Microsoft (Internet Explorer) and NetScape (NetScape Navigator) to gain dominance in the usage share of web browsers.

The first non-beta version of Netscape Navigator (Source: ARN)

Netscape needed a lightweight scripting language for easier programming. This ultimately made web development more accessible, unlike other languages that required deeper training. In 1995, a NetScape employee, Brendan Eich, was given ten days to help build the company a lightweight scripting language. As a result, Eich built Mocha, which was later renamed JavaScript.

The moral of the story — JavaScript was never intended to become the standard language for the web! However, after NetScape was acquired by AOL and eventually turned over their browser’s code to the Mozilla Foundation, the popularity of JavaScript grew.

JavaScript is now an essential web technology that’s supported by the most popular web browsers. Familiarity with the language is crucial for anyone who wants to become a web developer — that’s why it’s been the most commonly used programming language in Stack Overflow’s Developer Survey for six years in a row.

The most popular programming languages in Stack Overflow’s 2018 Developer Survey.

JavaScript’s Popularity

At this point, you may be wondering: how is it that a language written in 10 days by one person became mass-adopted by the world wide web? In short, JavaScript became a hit because it turned web browsers into application platforms. Here’s how:

  1. JavaScript can be used in both the front-end and back-end of web development.
  2. JavaScript is standardized, so it’s frequently updated with new versions.
  3. JavaScript works with the document object model, or the DOM, to respond to user interactions. The DOM is the structure in the browser that displays a web pages.
  4. JavaScript allows websites to have interactivity like scroll transitions and object movement. Modern browsers still compete to process JavaScript the fastest for the best user experiences. Chrome, the most used Internet browser in 2017, has been so successful in part because of its ability to process JavaScript quickly.
  5. JavaScript offers a wide range of frameworks and libraries that help developers create complex applications with low overhead. Programmers can import libraries and frameworks in their code to augment their application’s functionality.

Features of JavaScript

JavaScript does have some special features that make it such a popular language. Javascript is a very handy language to learn today since almost every website uses it. The coolest part of javascript is, you don’t need prior knowledge of any programming language.

General JavaScript Features

JavaScript language consists of several different features. Some of the general JavaScript features are as follows –

1. Validating User’s Input

JavaScript is very useful while using forms. It has the capability to validate user input for errors and also saves time. If the user leaves a required field empty or the information is incorrect, JavaScript checks for them before sending the data over to the server.

2. Simple Client-side Calculations

Since JavaScript is a client-side technology, it can perform basic calculations on the browser. The browser does not need to ask server time for every task. This is especially helpful when a user needs to perform these calculations repeatedly. In these cases, connecting to the server would take a lot more time than performing the actual calculations.

3. Greater Control

JavaScript provides greater control to the browser rather than being completely dependent on the web servers. JavaScript provides various browsers with additional functionalities that help reduce server load and network traffic.

4. Platform Independent

Since browsers interpret JavaScript, it solves the problem of compilation and compatibility. Thus it can run on Windows, Macintosh, and other Netscape-supported systems. Also, it is possible to embed them in any other script like HTML that keeps JavaScript into use.

5. Handling Dates and Time

Unlike other programming languages, JavaScript has built-in functions to determine the date and time. Thus it is very easy to code only by using methods like .getDate().

6. Generating HTML Content

JavaScript has very handy features to dynamically generate HTML content for the web. It allows us to add text, links, images, tables, etc after an event occurrence (eg — mouse click).

7. Detecting the User’s Browser and OS

JavaScript is very capable in the detection of the user’s browser and OS information. Though JavaScript runs on every platform, there may occur a situation where we need the user’s browser before processing. This can be helpful for writing code that results in different outputs in different browsers.

Modern JavaScript Features

If we dive into some more recently added features of JavaScript that makes it unique from other programming languages. There are a lot more modern features of JavaScript invented after some general features. Some of them are as follows –

1. Let/Const

JavaScript has introduced the keywords ‘let’ and ‘const’ that are available to replace ‘var’. Unlike ‘var’, they are important due to their blocked scope i.e we can only access them in the block we defined them in. Whereas ‘var’, even if we initialize it inside a function, we can access it outside of the function.

2. Arrow Functions

These functions are very useful in simplifying the syntax and tamp down the lines of codes for the web page or web application. Since these are light-weight in syntax, they can be very easily used in anonymous functions in JavaScript.

3. Template Literal

This is a common feature in other programming languages that allows you to save variables directly into strings. This proves to be an important tool for developers as it permits them to focus more on the development of the application rather than spending the time on syntax.

4. New Array Functions

Though array functions are not necessary for any programming language, they do simplify things for the developer. This also compacts the code and makes it much easier to understand. A regular array and an associative array, JavaScript supports them both. While a regular array contains integer values for its index, indexes can be strings for an associative array.

5. Default Parameters

This JavaScript feature helps to avoid collapsing the whole code for a simple mistake. It is very useful when the developer needs to check the working of a function without any parameters.

6. Property Shorthand

Built-in methods like .get() are available for the developer’s use. These methods help avoid writing the same code every time and cut back on various lines of code. These inborn methods are really supportive of cutting back the developing time and cost.

Uses of JavaScript

1. Web Development

JavaScript is a client scripting language which is used for creating web pages. It is a standalone language developed in Netscape. It is used when a webpage is to be made dynamic and add special effects on pages like rollover, roll out and many types of graphics. It is mostly used by all websites for the purpose of validation. In addition to validations, it supports external applications like PDF documents, running widgets, supporting for flash applications etc. It can also load content into a document whenever the user requires it without even reloading the entire page.

2. Web Applications

With technology browsers and personal computers have improved to the extent that a language was required to create robust web applications. When a user explores a map in Google Maps then the user just needs to click and drag the mouse. All detailed view is visible by just a click. This is possible due to JavaScript. It interacts with the browser without sending messages to and fro to the servers. JavaScript uses Application Programming Interfaces(APIs) that provide extra powers to the code.

3. Presentations

JavaScript also provides the facility of creating presentations as a website. JavaScript provides RevealJS and BespokeJS libraries to build a web-based slide deck. Reveal.js creates some of the most beautiful and interactive decks using HTML. A user can easily insert nested slides. Even if the user is not aware of programming language then they can easily build a site with so much help online. These presentations are touch optimized and work great with mobile devices, phones, and tablets. With all this JavaScript also provides different transition styles, themes, and slide backgrounds. It supports all CSS color formats. JavaScript also provides Bespoke.js plugin with a wide variety of features. These include responsive scaling, animated bullet lists, and syntax highlighting for code examples. It provides themes which are polished and not too flashy. The quickest way to start Bespoke.js is using a generator. It allows the user to set titles to your presentation and go through a set of questions to get the plugins required.

4. Server Applications

Node JS is built on Chrome’s Javascript runtime for building fast and scalable network applications. It uses event-driven, lightweight and efficient applications which are to be distributed over the systems with the help of a server. Javascript is used to handle HTTP requests and generate contents. When a user is writing thick applications in JavaScript on the client then a user may even write the logic in JavaScript on the server so that cognitive leaps can be done from one language to the other.

5. Web Servers

Using Node JS a web server can be created. The advantages of Node JS are that it is event-driven and would not wait for the response of the previous call. It moves to the next call and takes advantage of events to get notifications when a response is received for a previous call. The servers built on Node JS are very fast and do not use buffering and transfers chunks of data. In addition to this, it is single threaded with event looping which is used in a non-blocking way. The HTTP module can help in creating a server by using the createServer() method. This method is executed whenever someone tries to access port 8080. In response to this, the HTTP server should display HTML and should be included in HTTP header. It can be installed easily by typing ‘npm install -g http-server’ and it can be started by typing http-server command.

6. Games

Not only websites but uses of JavaScript also helps in creating games for leisure. The combination of JavaScript and HTML5 makes JavaScript popular in games development as well. It provides the Ease JS library which provides simple solutions for working with rich graphics. It also has an API that is familiar to all flash developers with a hierarchical display list. A user can create a Stage and it will render the display list to its target canvas. Ease JS also has 2D bitmaps called Sprites which are drawn directly to render the target for transformations.

7. Art

Using the HTML5 in JavaScript drawing graphics on a web page has become easier. All two and three-dimensional shapes can be easily drawn on a canvas and this has opened the browser as a new medium for all different digital art projects. A canvas has no border and no content and hence lets the user create his own art.

8. Smartwatch Applications

Javascript being the most used language is because it is being used in all possible devices and applications. Uses of JavaScript provides a library Pebble JS which is used in smartwatch applications. This framework works for applications that require the internet for its functioning. Using Pebbles allows a developer to create an application for a number of watches using JavaScript.

9. Mobile Applications

The most important thing that can be done by the uses of JavaScript is building applications without web contexts. Mobiles being mostly available in Apple and Android two different languages are used to build these. It should be possible to write once and use it on both platforms of these devices. PhoneGap is the framework which enables this. Also recently we have React Native that serves this purpose. It is the major player in cross-platform changes and deployments. Hence uses of Javascript can be used to deploy and download the respective applications across cross environments.

Which Companies Use JavaScript

Microsoft

Okay, so you’re probably not going to find JavaScript powering Windows anytime soon, but Microsoft relies on JavaScript for a whole lot else.

First off, Microsoft needs to work closely with JavaScript to built its Edge web browser. All browsers need to process and execute JavaScript efficiently, so Microsoft has developed and maintains its own JavaScript engine for Edge. Actually, there has been talk of them creating an alternate version of NodeJS with the Edge engine.

Recently, Microsoft has really embraced NodeJS. They thoroughly support Node on the Azure cloud platform. Its one of Azure’s major features, and they’ve integrated Visual Studio support for Node.

Microsoft has also developed a version of Node for Internet Of Things(IoT) applications. NodeJS is great of IoT because it’s light weight and efficient.

PayPal

PayPal has obviously been using JavaScript on the front end of their website for a long time, but that’s only the beginning.

The online payment giant was one of the earliest adopters of NodeJS. During an overhaul of their account overview page, they decided to try building the page in Node at the same time as their usual Java development. The NodeJS version worked out so well, that they chose to use it in production and build all client-facing applications in Node going forward. That means that most of what you see in your account is running on Node.

PayPal even went as far as to create and maintain their own version of Express, called KrakenJS. It’s pretty obvious that they like JavaScript over at PayPal.

Netflix

Like PayPal, Netflix started out using Java for just about everything. They too ran into problems with Java’s size and the time it required to develop.

Over time, Netflix moved away from its more traditional structure into the cloud and started to introduce NodeJS. With Node, Netflix was able to break down pieces of their user interface into individual services. This more distributed approach was able to speed things up an alleviate stress on their servers. Today, a large portion of Netflix’s interface is running on Node.

Uber

Uber needs to handle loads of data in real time. They have millions of requests coming in continuously, and that’s not just hits on a page. Uber needs to track driver locations, rider locations, and incoming ride requests. It has to seamlessly sort that data and match riders as fast as possible.

All of that plays to NodeJS’s and JavaScript’s strengths. Node is designed to handle requests and hand off data quickly. It’s asynchronous capabilities are a huge part of that. Node is central to Uber’s user facing stack for just that reason.

Facebook

You’re probably aware that Facebook uses JavaScript. It’s kind of hard to miss. What’s probably not as obvious is exactly how much JavaScript goes into making Facebook and how much Facebook is involved in JavaScript development.

Try disabling JavaScript in your web browser and going to Facebook. The website will actually stop you from logging in because it won’t work without JavaScript.

You may have noticed the way that Facebook loads. Each piece of the page is separate. Facebook has invented its own way of breaking down and delivering sections of JavaScript separately. In an odd way, each section of your Facebook page is a collection of independent JavaScript applications.

It doesn’t stop there. Facebook created React, one of the most popular front end frameworks. Facebook uses React on Facebook.com as well as Instagram and WhatsApp.

Google

How doesn’t Google use JavaScript? Seriously, it’s everywhere. Google’s search results that spring up as your typing get there with JavaScript. The Gmail web client is powered by JavaScript. Google Docs? Yeah, that’s JavaScript too.

Google develops and usually open sources it’s own JavaScript tools. The most obvious example is AngularJS. Angular is used most prominently in Google’s DoubleClick advertising platform, but it’s also one of the most popular front end frameworks available. It’s even part of the MEAN stack.

Google’s more intensive services, like Google Docs, use Closure Tools. This set of tools compiles JavaScript into a lower-level faster form more suited for rich and highly responsive web applications.

There’s another big point to touch on. Google developed Chrome. Chrome, being a web browser, needed a JavaScript engine, so Google also made V8. V8 not only powers Chrome, it’s at the heart of NodeJS. So, without Google, there would be no Node.

That’s all folks. Hope you enjoyed 😊

Demo

Here is a small project demo I built using JavaScript integrated with Python-CGI and Docker:

GitHub: https://github.com/Prithviraj-Singh/javascript_docker.git

--

--