Intro to modern JavaScript frameworks
Nov 5th, 2021
JavaScript, which was originally named Mocha, has been in use on the internet for more than 25 years. It was originally designed as a client-side scripting language, but despite being around since the early days of the internet, it has constantly evolved to meet the challenges associated with today's application development. Modern JavaScript is a powerful server-side language as well.
JavaScript is a multi-paradigm language that supports both procedural and object-oriented programming. As JavaScript has evolved, it has also come to support event-driven imperative and procedural programming styles as well.
In this guide, we will explore some of the most popular JavaScript frameworks being used by developers today, and we will discuss how to get started using these frameworks to build your own applications.
What is a JavaScript framework?
JavaScript frameworks provide developers with pre-written code for common programming patterns. By abstracting away many of the tedious tasks involved in setting up and running an application, these frameworks allow developers to focus on building the features of their applications. These frameworks serve as a tool for organizing and structuring applications and websites, making the development process easier and faster.
The terms library and framework are often used interchangeably, but it is important to distinguish the two terms. By providing a toolkit of features, a framework acts as a foundation with which developers can build and design their applications. Based on this foundation, developers can add features as needed to their applications. In contrast, a JavaScript library consists of pre-written code snippets or functions that provide specific functionality. By using these libraries in conjunction with a framework, developers can benefit from the best of both worlds, since they will have the features they need if the framework does not already include them.
As an example, the Angular framework provides a comprehensive foundation for developing single-page web applications. When developing an Angular application, developers may find that they have to manipulate datasets using array functions. It is possible for developers to implement array manipulation functions themselves, or they can use a JavaScript library, such as Loadash, which comes with a wide variety of pre-written array manipulation functions that can be used as required. Based on the requirements of the application, developers can choose from a variety of JavaScript libraries whether they come from organizations or popular open source communities.
Five most popular JavaScript frameworks and libraries being used today
This section describes five of the most popular JavaScript frameworks and libraries that are used today. As each framework offers its own set of features and trade-offs, developers will need to consider these carefully when deciding which one is most suitable for their application's needs.
React
According to the 2021 Stack Overflow Developer Survey, React was voted as the most popular web framework, with over 40% of survey participants reporting it as their preferred framework of choice. React is a library that is developed by Facebook to simplify the process of building interactive UIs. In React, data from a component is bound to the DOM using one-way data binding. As a result, the state of data can be updated by events, and has better performance.
Some of the key features of React include:
- Declarative programming paradigm: In React, declarative programming allows a developer to control the flow and state of a component by telling it what it should look like, rather than how it should do it.
In an imperative programming approach, controlling the state of a like button would work this way:
if( user.likes() ) {
if( hasBlue() ) {
removeBlue();
addGrey();
} else {
removeGrey();
addBlue();
}
}
However, the same process using a declarative approach in React would look like:
if( this.state.liked ) {
return <blueLike />;
} else {
return <greyLike />;
}
- Component-based architecture: In a component-based architecture pattern, the user interface is composed of smaller individual pieces or components that function independently.
- React native as a custom renderer: When developing with React, users can develop a version of the app that supports one platform. Developers can then use custom renderers to add support for other platforms with little effort. One of these renderers is React Native, which is used on iOS and Android platforms.
- A virtual DOM: React makes use of a virtual DOM that is updated whenever an application's UI is modified. When changes are made, a delta (difference) record is generated, where only the parts that have changed are re-rendered. As a result, UI updates with React are faster and more efficient than using traditional methods of updating the full DOM structure.
- JSX Syntax: React also uses JSX syntax, an extension of JavaScript that allows developers to directly use HTML within JavaScript code.
Node.js
Node.js isn’t necessarily a JavaScript framework like React, but is rather a run-time environment that is capable of driving asynchronous I/O with event-driven architecture. Node.js is often used in server-side applications and is well suited for applications using a microservice architecture.
Some of the features it offers include:
- Open source: Node.js is maintained by the open source community. The Node.js community has developed and maintained a large number of packages, which are made available and hosted on the npm registry.
- Single-threaded architecture: Node.js, like JavaScript, is single-threaded with code running on the main thread in tandem with an event loop and callback queue that respond to events that arise during execution.
- Performant: Node.js runs on a single-thread event loop, and this may sound less performant than a multithreaded solution such as Java. The beauty of the event loop is not of running everything in a single thread, but that it’s available to put aside long time-consuming I/O operations to unblock the execution of other instructions.
- Highly scalable: If you make use of the cluster Node.js module, you can distribute incoming connections using a round-robin strategy, making your app highly scalable.
- Compatible with the Fauna Node.js driver: Fauna offers a JavaScript driver that is compatible with Node.js. The driver allows you to configure connections to your databases and execute queries.
The driver can be installed in your Node.js project by running:
> npm install --save faunadb
Angular
Angular is a JavaScript framework that originated from Google, commonly used to develop single-page web applications. While Angular is not as light-weight as a React library, it is a more full-fledged application framework that includes a number of libraries that make it easier to build complex applications.
Some of these features include:
- Easy development of progressive web apps: A progressive web application takes advantage of the latest technologies to combine the best of web and mobile apps. With progressive web applications, there is no need to download and install anything.
- Code generation: Angular has a code generation service that generates Angular components based on user-provided metadata.
- Code splitting: Angular uses code splitting to modularize a large monolith application into smaller bundles. Using optimizations such as lazy loading, these smaller bundles can be loaded or rendered on demand whenever they’re required.
- Templates: Angular uses templates similar to HTML templates for rendering views. These templates, however, offer more functionality, such as data binding.
- IDEs: With angular, modern IDEs offer features such as smart code completion when developing applications.
- End-to-end testing: Angular applications can be end-to-end tested to emulate real world usage using testing frameworks such as Cypress.
Vue.js
Vue.js is an open source model–view–viewmodel front end JavaScript framework used to develop user interfaces and single page web applications. This framework was developed by Evan You, a former Google engineer who wanted to use some of the features he liked from Angular in his own light-weight framework.
Some of the features that Vue.js offers includes:
- Ease of use: Vue.js uses standard JavaScript which is easier to use as compared to other frameworks and libraries such as React that uses JSX.
- Virtual DOM: Like React, Vue.js also uses the more efficient virtual DOM.
- Data binding: Vue.js makes use of two-way data binding. Here, data is shared between a component class and its template. Changing data in one place will automatically reflect on the other end.
- Easy implementation of CSS styles: CSS styles such as animations and transitions can be easily implemented in Vue.js using the v-bind directive.
<div
class="static"
v-bind:class="{ active: isActive, 'text-danger': hasError }"
></div>
- Provides HTML-based templates: Vue.js uses HTML based templating to which event-handlers and styles can be added through the use of directives.
Ember.js
Ember.js is another JavaScript framework used to create applications using a component-service pattern. Ember has grown in popularity in recent years for its use in creation of beautiful and advanced UIs. It’s used by LinkedIn and Netflix, among others.
Some of its features include:
- HTML and CSS development: Ember.js focuses on the development of the HTML and CSS model at its core to enable developers to create more stylized applications.
- Ember Inspector: Ember Inspector is a browser add-on that aids developers in understanding and debugging their web applications.
- Templates: Ember uses HTML templates to drive its UIs. Each piece of the UI displayed to a user is defined by an HTML template.
Conclusion
With modern JavaScript frameworks, developers can easily create beautiful, engaging applications. Here’s the best way to get started with a new framework:
- Read the user documentation. Each of the frameworks and libraries discussed above contain links to their official documentation which are usually a very good resource for diving into them.
- Try out the starter applications. Most of these frameworks have a starter application in their quick start guides, making it very quick and easy to set up.
- Discover which frameworks are suitable for a given scenario. As you play around with these sample applications and frameworks, you can draw comparisons to the frameworks you already know about. Take note of the differences and benefits you see when using these frameworks.
- Select a framework that meets your requirements. Once you’ve played around with a couple of frameworks, you may select one that is best suited for the needs of your application. You can then begin sketching out how it’ll be used on your codebase.
- Leverage the features and the benefits of the community. You can now start implementing features and slowly build out your application. Most of these frameworks have large user-bases, making it very easy to reach out to the community for support when you run into trouble.
When building applications using any of the frameworks above, it’s still critical to have a stateful database to keep your applications dynamic. Fauna is a serverless, developer-friendly database with a JavaScript driver making it easy to integrate in your JavaScript applications. Fauna also has a GraphQL API to query data, making it a familiar language for JavaScript developers to query data from Fauna.
Sign-up for free
Sign-up for Fauna for free without a credit card and get started instantly.
Quick start guide
Try our quick start guide to get up and running with your first Fauna database in only 5 minutes!
If you enjoyed our blog, and want to work on systems and challenges related to globally distributed systems, serverless databases, GraphQL, and Jamstack, Fauna is hiring!
Subscribe to Fauna's newsletter
Get latest blog posts, development tips & tricks, and latest learning material delivered right to your inbox.