Skip to content
bebraw edited this page Apr 21, 2013 · 4 revisions

Particularly in the last few years the usage of JavaScript has grown explosively. Instead of using it to sprinkle some functionality to their sites some people are using it to manage the whole stack from backend to frontend. This has been possible thanks to the increasing popularity of Node.js. A whole ecosystem has grown around it. Particularly NPM has been an important factor in this growth as it has allowed people to share their modules and use ones created by others.

Traditionally this has been a weakness of JavaScript as it does not come with a de facto module system. Let's just say the situation is still a bit messy although it is getting better on the frontend side thanks to solutions such as RequireJS and browserify. The former implements a module definition known as AMD whereas the latter allows to use module semantics familiar from Node on the frontend side.

Better yet ES6 may finally solve this issue once and for all. I definitely hope so. Even still there will likely be a period of time where ES6 compatible code will be transpiled into ES4 format.

Might Run on Your Toaster

What makes JavaScript interesting is the fact that it is supported by a wide range of hardware already. Just imagine the mobile devices around that can execute it. Most likely you already have one in your pocket. And that is not counting all the desktop systems. It is as ubiquitous as a language can get. In some ways it can be considered the assembly language of the web generation. It is that important.

Even though traditionally JavaScript has been thought as a language to be used in web browser, you may use it in various other contexts as well. Node.js provides an example of a server-side usage. Apache Cordova is an example of a framework allowing you to develop applications in a mobile context. Compared to pure browser based services the platform yields a better access to the hardware.

It is possible to use JavaScript to control electronics, possibly including your toaster. Look around for various Node.js libraries. You will also find support for the popular Arduino platform.

There are APIs and APIs

Even though it is widely supported it takes more than just a language to make something useful. That is where browser and server-side APIs come in. Sometimes the APIs aren't particularly easy to use. As the popularity of jQuery shows there is sometimes demand for solutions that make them easier.

In this case DOM operations are made considerably easier or at least more compact. jQuery allows you to chain various methods and build some form of interactivity quite easily. It does have its limits, though. The fact that it relies on a query syntax resembling CSS provides a natural entry point. The example below sets all headers of a page red for instance. In case you are using Chrome, you may give it a go at the JavaScript console (View -> Developer -> JavaScript Console, or Command-Alt-J for the hipstery kind).

$(':header').css('color', 'red')

The example shows how to use one powerful pseudoselector of jQuery, namely :header. jQuery also uses a powerful pattern known as chaining.

More Powerful, More Standard

During the last few years we've progressed a lot on the browser side. JavaScript engines have become more powerful. This trend was initiated by Google's Chrome and has since led to significant improvements in performance. Standards are supported better. Thanks to Microsoft and its initiatives with Internet Explorer 9 and 10 they've started to catch up with the others and in some ways gone past even. That is a good trend for us web developers as gradually we may start to ditch legacy solutions needed by antiquated browsers such as Internet Explorer 6.

There is still a lot to be done. In case you decide to support only a limited set of modern browsers, you are in luck. At times you may use specific shims in order to be able to use newer features at older browsers. I often use caniuse.com to see whether or not I should use something yet and if so, how.

Sometimes you might want to use certain feature on certain device type while avoid using it on another. A good example of this is hovering. Given there is no hover state on mobile devices, it is definitely something you don't want to use there. Modernizr has been designed to solve this problem. It works on feature level and is a very good fit for this case.

In the olden days people used to check for specific browser. Generally this isn't considered a good idea given the browsers may fake their identifying information. So better not to use that unless you really know what you are doing.

Still Hope for Newbies

If you have not hopped into the JavaScript train yet, it is a good time to do so now. It's not too late. In fact a lot of development is going on. Newest developments include the introduction of MVC frameworks on the frontend side. Reactive programming is another newcomer.

It is funny how sometimes old concepts are new again. I guess that might have something to do with programmer generations and the development of hardware. Old, discarded techniques become feasible as hardware isn't the constraint anymore. Or we're just good figuring out how to make even the new machines crawl.

There has also been development on the asynchronous side. Solutions have been provided that allow us to deal with callbacks in better ways. Promises for instance obscure callbacks altogether and provide a declarative alternative for them. In a way reactive programming is yet another solution.

If that sounded like technobabble to you, don't worry. I still recommend researching the concepts. There should be plenty of material available.

ES6 - The Future

The language itself is headed towards a brighter future with ES6. The specification promises to bring forth improvements such as long awaited modules, several language constructs and overall just standard ways of doing things so we can avoid reinventing the wheel ourselves. In fact you can mimic some of the planned features already but obviously it won't look or feel as good. On example of this is generators. I'll discuss this particular case later at Language Features.

Even if ES6 was finalized tomorrow, it will take quite a while for browsers to catch up. Thanks to legacy and the fact that we cannot go and update everyone's software to support the newest tricks there will be a transition period. The most likely scenario is that those who wish to adopt ES6 features will include them into their builds and transpile the code into something that is ES4 compatible. This situation is not far from what people are doing already with languages that compile into JavaScript and seems very realistic to me.

It is possible that ES6 efforts fail for a reason or another. That is not my problem, though. In fact you can use some of the features already if you really want. Just find a transpiler. I would avoid this for now while things settle down.

Conclusion

I hope you have a better idea of where JavaScript is right now and where it is headed. So far we've managed to see only one line of code. It is getting really boring for the most antsy of us. So it is the right time to have a peek at some of the Language Features.