Article

5 New Possibilities With JavaScript

February 01, 2016  |  Pluralsight
Learn something new. Take control of your career.
Sign up

JavaScript was created a little over 20 years ago with the primary use of manipulating HTML pages in web browsers. It allowed people to interact with static content on web pages without needing to reload the page. Some original common use cases for JavaScript were to validate forms in real time, animate elements on a page, and dynamically load new content. Now fast-forward to today and you’ll see the language has come a long way, and it’s not restricted to running only in web browsers anymore. Those of you who are familiar with JavaScript most likely learned it by implementing some of those use cases I just mentioned, but today I want to go over some awesome — yet not-so-commonly known — areas where you can use JavaScript.

Prerequisite: Node.js

If you’re learning JavaScript today, you’ll most likely also want to learn Node.js. All of the following topics require the use of Node in some way, which is why I want to mention it as a prerequisite. Node is basically a runtime environment that allows you to develop server-side web applications in JavaScript that let your application communicate with databases, file systems, data streams, and more. With Node, it’s possible to create applications that are written completely in JavaScript, as opposed to using a different language — such as Python, PHP, or Java — to handle the server-side requests as was the norm several years ago.

1. Robotics

It’s really easy to get started doing some robotics programming with JavaScript. To get started you’ll need:

  1. A compatible Arduino microcontroller.
  2. Node installed on your computer.
  3. The Johnny-Five node module.

Arduino boards are small microcontrollers that are capable of reading input — for example, a light or touch sensor that produces some sort of output, such as flashing an LED light or spinning a motor. The classic “Hello World” program of the microcontroller world is getting an LED light to blink, which is really easy with JavaScript. Here’s the example:

You can view the whole installation process and more code examples on GitHub. NodeBots is a group that hosts events focusing on JavaScript robotics, and they have a ton of fun and interesting projects created by the community that you can see on their website.

2. Drones

Drones, or more accurately quadcopters, are becoming increasingly more popular, and of course there are now ways to control these drones via JavaScript. The most popular programmable drone is the Parrot AR Drone 2.0. It costs between $250-300, and to write programs that control the drone you’ll need to have Node installed on your computer. Once you have these two things, there are over a dozen node modules that allow you to control the drone via JavaScript. For example, you can control the drone using an interface within your browser, using a Wii controller, or you can even have your drone fly autonomously and take panoramas.

You can also use the bare-bones node-ar-drone module and write your own programs to control the drone. A simple program that gets your drone into the air, rotates it, flips it, and then lands it looks like the following:

3. Intensive Computations and Algorithms

When compared to lower-level languages, such as C or Java, JavaScript is usually outperformed drastically in terms of speed and performance. A partial solution to this is asm.js, which is simply a strict subset of the JavaScript language with some constraints and optimizations that allows programs written using asm.js to run at near-native speeds. A good example of an application where asm.js would be useful is a chess program where the computer needs to run several algorithms performing thousands of computations a second to determine the next best move in the game.

If algorithms, optimization, and performance interest you, there are several websites devoted to coding challenges that range from simple string manipulation to more advanced algorithms. Some popular websites are HackerRankCoderbyte, and TopCoder.

4. 3D and Virtual Reality

It’s now possible to create virtual reality scenes in your browser or on your mobile device with JavaScript. Most tutorials and games you create will require three.js, which is a 3D JavaScript library that allows you to easily create 3D scenes and manipulate them. You can see what three.js is capable of with this Minecraftexample.

To create virtual reality scenes in JavaScript, the easiest way to get started is to first get a Google Cardboard headset, which you can find for less than $20, and then set up three.js along with a few other JavaScript libraries. Check out this tutorial, which explains how you can get started. If you already own a Cardboard headset, you can also check out Chrome Experiments to experience virtual reality on your mobile device.

5. Mobile Applications

With the recent release of React Native, it’s now possible to build native phone applications entirely in JavaScript! React Native is a framework that allows you to create mobile apps that actually use native components and function like native apps, but you don’t have to learn a new language, such as Swift or Java, to get started — you’re able to use JavaScript. The Facebook team behind React Native also built this to work with iPhone and Android devices. Below is a small sample of what this JavaScript code looks like for Android:

JavaScript is a great language, and every day there seems to be more and more possibilities with it. These are just a few options I’ve found that are less common, but if you have any you’d like to recommend or talk about, I’d love to hear about them. Let me know in the comments section below!

Learn something new. Take control of your career.
Sign up

Pluralsight

Pluralsight is the technology learning platform. We enable individuals and teams to grow their skills, accelerate their careers and... See more