Developers

Why JavaScript is used in IoT

In 1995, JavaScript emerged as programming language to create web pages. Brendan Eich developed JavaScript with syntax similar to C, but nobody believed that JavaScript would play a major role in development of commercial softwares. In 1997, JavaScript was made a standard through ECMA international. But what gave the required firepower to JavaScript from breaking out of just being a programming language to creating web pages are the

  • The creation of JavaScript Standard Object Notation (JSON)- data interchange format, as a strict subset of JavaScript by Douglas Crockford and
  • The introduction of Node.js in 2009 by Ryan Dahl. Node.js has played a crucial role in building web servers in JavaScript by using Google’s super fast V8 JavaScript engine.

Now JavaScript is widely used in web pages, web servers, mobile apps, and IoT systems.

You ask me why JavaScript is used in building IoT systems? Here are my reasons.,

JavaScript is a event-driven language

It is quite good at event-driven applications. In event driven applications, every device listens to various other events and responds to concerned events.

Event loops in JavaScript allow you run numerous tasks without waiting for other tasks to complete. This helps in responding to events in real time, handling multiple tasks parallelly, and allowing multiple devices to respond to the same event. This contributes to a great extent in saving precious battery power.

Memory management

JavaScript has a garbage collector, which eliminates the need of explicitly freeing up the memory. This allows embedded developers to focus on other important aspects of development. The automatic freeing of the unused memory results in a stable product because the garbage collector eliminates memory leaks.

One drawback of garbage collector with constrained devices is trashing – the garbage collector running very often has an adverse impact on performance. This can be avoided with the JavaScript programming style which limits the creation of new objects to major state changes in the embedded device or application. This keeps the memory usage stable without running the garbage collector very often.

Existing JavaScript tools, libraries and plugins

With the increased use of JavaScript in various applications, there are many JavaScript development resources available, such as

  • JavaScript libraries like Underscore.js, lodash, traverse, and Async
  • Testing tools like Blue Ridge, SugarTest, FireUnit, JSLint etc.
  • Client-side development framework
  • Server-side JavaScript APIs and others

JavaScript developers in IoT have sophisticated frameworks and engines like CycloneJS, IoT.js, JerryScript, Duktape, etc. specifically designed for constrained devices.

JavaScript compatible hardware solutions

A wide variety of hardware solutions in IoT, such as Raspberry Pi, Espruino, etc.. support Node.js. There are JavaScript-only microcontrollers such as Tessel 2 and Espruino which have proven to be very useful in IoT projects. Thousands of Node Package Manager (NPM) modules for Node.js such as PM2, Socket.io, Mocha etc. have been developed to enhance the power of Node.js in IoT.

End-user scripting

End user scripting can be enabled by embedded devices using JavaScript because JavaScript is a managed execution environment where end-used scriptability is secure by safely sandboxing the scripts. End-used scripting brings new ideas and possibilities because the customization enabled by allows end-users, hobbyists, and professional programmers to script their devices and add new functionalities.

JavaScript is open source

This is another crucial factor that makes JavaScript a suitable programming language for IoT. The open source nature of JavaScript makes it possible for programmers to make useful contributions to various JavaScript projects. This fosters creativity and brings in innovations to IoT enabled hardware, software, and network solutions.

JavaScript is widely used across internet

Already JavaScript is a commonly used language across the Internet, so it makes absolute sense to include the same language in the devices which will be part of the Internet.

JavaScript is easy to learn

JavaScript is very easy to learn, so you can start coding in a short span of time. Consider a situation where a C programmer is asked to do parallel programming.

To do parallel programming in C, he has to be a “stud.” He has to know what he is doing. And here is this JavaScript thing; it is kind of a built-in feature. Now any 12-year-old can do parallel programming!

Familiar Syntax

Currently, a majority of embedded programmers are using C. In the process of developing an IoT system,  embedded programmers need not learn different syntax if they are using JavaScript. Syntax of JavaScript is very similar to C, hence an experienced embedded programmer just needs to invest a little time to understand and successfully modify JavaScript code.

Popularity of Node.js !

Node.js has evolved as a robust technology which makes server-side implementation of JavaScript possible. The event-driven nature and asynchronous input-output (IO) model of Node.js makes it a perfect fit to build IoT systems.

A range of tech majors are leveraging the power of Node.js in building a network of devices, sensors, and smartphones; these can be controlled and manipulated remotely. Companies like Microsoft, IBM, and Samsung have already embraced Node.js as the preferred technology for their IoT development projects.

So now,

Vasudhendra Badami

Vasudhendra Badami is a category head (IoT) at HackerEarth. A writer by day and a reader by night. Covers topics like Internet of Things, electronics and analytics. You can find Vasudhendra on Twitter (@BadamiVasu)

Share
Published by
Vasudhendra Badami

Recent Posts

Top 10 HR Competencies to Build a Strong HR Department: A Comprehensive Guide

Introduction In today's dynamic workplaces, a strong HR department is no longer a luxury –…

7 hours ago

8 Steps for Conducting a Job Tasks Analysis: A Complete Guide

Job task analysis is a crucial process for understanding the specific duties and skills required…

8 hours ago

Top 8 Sourcing Tools for Recruiters: A Comprehensive Guide

In today's competitive talent landscape, attracting top candidates requires going beyond traditional job board postings.…

8 hours ago

The 12 Most Effective Employee Selection Methods: A Comprehensive Guide

Finding the perfect fit for your team can feel like searching for a unicorn. But…

8 hours ago

12 Important Recruiting Metrics You Should Know

Recruitment forms a strong foundation to build an effective team. However, do you know if…

12 hours ago

7 Modern Performance Appraisal Methods to Boost Workforce Development

Introduction Performance appraisal has seen a tremendous change over the years. It is no longer…

1 day ago