JavaScript for Dummies — Part 2

In my previous blog, we looked at the properties of JavaScript and their (dis)advantages. We saw that JavaScript is easy to read, allows for compact, flexible code and improves maintainability and development time. However, it is runtime inefficient, and troubleshooting is hard, which can be a pain the ass, indeed. So why are programmers using this language so much, and what can you actually do with it? Lets look at a few advantages of using JavaScript, focussing on the web and app development branch.

Interactivity

So, interaction is clearly a good thing to build into a website, but why use JavaScript for this, risking many unexpected bugs and inefficient runtime? As you might know, a web page is built with HTML, the skeleton of the page. This skeleton can be dressed using CSS; which means styling the page statically. JavaScript can then be used to move the skeleton, and change or animate CSS properties; making the web page interactive. JavaScript is used as a client-side language, which means that the code is written into an HTML page by the browser (it runs scripts on your computer after you have loaded a web page). So, the script can interact with the HTML of the website by selecting elements of it and then manipulate those to provide the desired interactivity.

Why can we not use a server-side language to create interactive web pages? A server-side (or back-end) language runs its scripts before the HTML loads, not after. It is used for processing user input (like forms), structuring web pages and talking to the database. However, it cannot be used to create an interactive website. Therefore, client-side languages are used for interactivity. But there are more client-side languages besides JavaScript, like FLASH and Silverlight. So why would we use JavaScript? JavaScript is compatible with most browsers compared to other client-side languages, which is especially important when designing mobile websites and apps. Also, JavaScript is easier to use because it is fully integrated with CSS and HTML. Since JavaScript is so popular, many libraries and frameworks are available for this language (like jQuery and React). This is another important reason for using JavaScript instead of an alternative language.

Faster web page

JavaScript is weakly typed, which allows us to write code reasonably easily, without discipline or controls. However, this will reduce the performance of your app or website. To minimize the adverse influence of JavaScript on the runtime and only enjoy its positive effect, we can optimise JavaScript code in various ways. I will not discuss it here, but this website gives quite a good overview of what you can do to optimise performance.

Client-side validation

Building web and mobile apps all with the same language.

If you want to use JavaScript for building an app, you need a platform to do so. A platform used a lot nowadays is React native. This is a platform solely based on JavaScript, and the code is deployable to both iOS and Android. However, you still have to write some code specifically for Android and iOS if you want to create the native feel of an app because React native does not support things like push notifications. So, JavaScript can be used to build the basic functionality of the app, and you can choose to optimise it by using a native language additionally, but you do not have to.

Conclusion

So, once you familiarise yourself with the JavaScript language, you can build interactive, user-friendly apps and websites!

By Felicia. Felicia is a front-end developer at El Niño. She builds the visible parts of websites and applications and is starting to fall in love with Javascript ❤️

http://www.elnino.tech. Digital Development Agency building tailor made solutions, ensuring success by making it measurable.