Use Cases of JavaScript

Geetansh Sharma
8 min readJun 25, 2021

What is JavaScript?

JavaScript is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive. Where HTML and CSS are languages that give structure and style to web pages, JavaScript gives web pages interactive elements that engage a user. Common examples of JavaScript that you might use every day include the search box on Amazon, a news recap video embedded on The New York Times, or refreshing your Twitter feed.

Incorporating JavaScript improves the user experience of the web page by converting it from a static page into an interactive one. To recap, JavaScript adds behavior to web pages.

What is JavaScript used for?

JavaScript is mainly used for web-based applications and web browsers. But JavaScript is also used beyond the Web in software, servers and embedded hardware controls. Here are some basic things JavaScript is used for:

1. Adding interactive behavior to web pages

JavaScript allows users to interact with web pages. There are almost no limits to the things you can do with JavaScript on a web page — these are just a few examples:

  • Show or hide more information with the click of a button
  • Change the color of a button when the mouse hovers over it
  • Slide through a carousel of images on the homepage
  • Zooming in or zooming out on an image
  • Displaying a timer or count-down on a website
  • Playing audio and video in a web page
  • Displaying animations
  • Using a drop-down hamburger menu

2. Creating web and mobile apps

Developers can use various JavaScript frameworks for developing and building web and mobile apps. JavaScript frameworks are collections of JavaScript code libraries that provide developers with pre-written code to use for routine programming features and tasks — literally a framework to build websites or web applications around.

Popular JavaScript front-end frameworks include React, React Native, Angular, and Vue. Many companies use Node.js, a JavaScript runtime environment built on Google Chrome’s JavaScript V8 engine. A few famous examples include Paypal, LinkedIn, Netflix, and Uber!

3. Building web servers and developing server applications

Beyond websites and apps, developers can also use JavaScript to build simple web servers and develop the back-end infrastructure using Node.js.

4. Game development

Of course, you can also use JavaScript to create browser games. These are a great way for beginning developers to practice their JavaScript skills.

Why use JavaScript over other programming languages?

Aside from the unlimited possibilities, there are many reasons for web developers to use JavaScript over other programming languages:

  • JavaScript is the only programming language native to the web browser.
  • JavaScript is the most popular language as of now.
  • There’s a low threshold to get started.
  • It’s a fun language to learn

Use of JavaScript In Online Games: Case Study

JS is considered to be the most popular and well-known programming language in the modern world. Its popularity is caused by a number of reasons, including user-friendly code and versatility. Indeed, JavaScript can also be an excellent helper when developing online games. Its scripts make it possible to easily combine JS codes with HTML5 and CSS, thereby creating excellent cross-platform applications.

Is It Possible to Create a Proper Online Game Using JavaScript?

Of course, this is possible. There are many 2D and even 3D games created using pure JavaScript or its frameworks. You can find a really huge number of libraries and frameworks, written in JS, but aimed at HTML5 games development, for example — Feather. Games made with JS will not always be native, but this does not make them worse.

Creating a game on JavaScript is not only possible but also simple. In fact, you don’t even have to use Node.js or bother with the server-side of the project. All you need is a basic knowledge of JavaScript and CSS. Still, the required amount of knowledge depends on how complex your game will be. Obviously, you will need more skills to create a large-scale RPG. At the same time, you need literally basic knowledge to develop a simple platformer.

On the web, there are many various step-by-step tutorials aimed at helping you with your first online game. Decide which game you want to develop and proceed to the next step — choosing a library and engine. We have listed the best of them below.

Best JavaScript Engines to Build Web Games

PhaserJS

Phaser is one of the most popular choices among developers when creating an online game. Its database is open-source, and a large community of developers will be there to help you grasp all the processes and find answers to many questions. Phaser uses a built-in JavaScript library — PixieJS. This allows for seamless interaction between WebGL and Canvas elements.

This framework is great for beginners because it handles most of the game automation processes. Thus, you do not need to write long code for each element of your game. Physics of objects can also be achieved using special external libraries. Ultimately, your game produces a very professional feel thanks to the objects’ realistic movements and behavior.

In fact, using Phaser and ready-made code from GitHub, you will roll out your first game after a couple of hours of work.

BabylonJS

Oh yes, this is one of the best frameworks for creating 3D browser games. It allows you to render objects of varying complexity, and you do not even need to write a lot of code. Creating a 3D object using a regular WebGL would take a lot of time and code. BabylonJS handles all the complexity on its own, so minimum efforts are required from you.

A few more features of BabylonJS are hardware scaling, a system of particles, smoothing, automatic scene optimization, and the ability to use 9 types of cameras with custom materials and shaders. Sounds good, doesn’t it?

MelonJS

This is a lightweight open-source framework that has a number of special features. First of all, this is a “plugin-free” tool for creating games on the “wrote once, launched anywhere” principle. The framework does not have such a large community as the two previous ones, but the developers who prefer Melon are its real fans.

Let’s list a few features of the framework:

  • lightweight 2D engine;
  • a simple HTML5 library;
  • compatibility with all popular browsers: Chrome, Mozilla, Opera, Safari, Internet Explorer;
  • compatibility with mobile devices;
  • lightweight physics with low requirements for your computer’s CPU;
  • built-in support for CocoonJS and Ejecta;
  • and so on.

In short, MelonJS is an ideal choice if your task is to create a simple lightweight 2D browser game with a minimal computational load.

Of course, there are many more of them. However, let’s look at some popular games created using JavaScript.

Examples of JavaScript-based online games

On/Off

Oh, this platformer will wrack your brain and freak you out. We have warned you! A beautiful and simple 2D-game with cool physics that pays respects to the Super Mario era. Play with headphones since fun music makes up 30% of the atmosphere.

Konnekt

That’s a great game for training abstract thinking. A virus has infected your system and you must move the nodes to save yourself from the total infection. Try it, but you need to read the rules first.

Everyone’s Sky

Oh, this is a full-scale space RPG that runs instantly and works in your browser. Explore space, enter into alliances or destroy your enemies.

1024 Moves

This game is a platformer where you need to move the cube through the map in an attempt to achieve the goal. The levels are full of small puzzles, switches, movable boxes, and so on. What may seem simple to you in the first round, will cause problems in the 6th. Oh yes, you only have 1,024 moves to complete the game!

All these games are a great opportunity to spend free time without buying, downloading, and installing anything. By the way, each of the above games is under 13kb of code. How do you like that? And there are lots of such games.

Summing Up

It is safe to say that JavaScript is used in online games. Yes, it isn’t so popular now, but its community and convenience promise a bright future for JS-based online games. It is mostly platformers and puzzles now, with a focus on the intellectual components of the game rather than on graphics or else.

On the other hand, every novice coder, who wants to create a game, can use JS for this. It won’t cause any problems, while the experience gained will be unique. The developer can show this game to their friends and discuss how to improve it. It is this unique experience that JavaScript brings to the game development sphere. With the help of JS, everyone has the opportunity to create their own game. Try it for yourself!

--

--