What is JavaScript?

JavaScript is often referred to as the browser scripting language, but it has also been extended to many server-side and mobile application development environments. JS has been around for nearly 20 years, and it is safe to say that it is a mature and stable programming language. JS became increasingly popular after Facebook released the React and React Native frameworks.

JavaScript has its own package managers, such as NPM and Yarn. Although JavaScript is now preferred and popular, there is still some mixed commentary within the programming community. It’s safe to say, however, that JavaScript’s popularity is indisputable, as it contains nearly 2 million issues flagged on StackOverFlow.

What is Dart?

Dart is a client-optimized language developed by Google for fast applications on a variety of platforms. Google originally used it as an internal programming language to build Web, server, and mobile applications. Although Dart has been around since 2011, it gained popularity after Google announced that Flutter was being developed as a cross-platform mobile application. The only reason is that Flutter is entirely based on Dart. Therefore, mobile developers must learn Dart to start using Flutter.

Dart compiles source code, similar to other programming languages such as C. But it also has its own virtual machine (VM) for running native applications called Dart VM. Dart also has its own package manager, called Pub.

Sample application using Dart and JavaScript

Dart.js

void main() {
  print("Hello World");
}
Copy the code

Javascript

console.log("Hello World")
Copy the code

JavaScript versus Dart

popularity

JavaScript is virtually everywhere, and there are few devices that don’t run JavaScript. Currently, JavaScript is used to write Web, mobile, and server-side code. JavaScript flagged nearly 2 million issues on StackOverflow.

Due to its popularity, the JS ecosystem is huge and now, with the emergence of cloud component centers, it even dominates the reusable component “market.”

Dart, on the other hand, is becoming more popular, but JavaScript is still a long way off. Dart was nowhere to be found before Google announced Flutter. Dart appeals to developers who do not support JavaScript. Dart currently flags nearly 30,000 issues on StackOverFlow.

The learning curve

JavaScript is notoriously tricky for beginners, especially if they have no background knowledge of programming concepts. But JavaScript is one of the main languages taught in universities and boot camps because it is one of the core languages of Web development. In fact, HTML, CSS, and JavaScript are called the triumvirate of Web development. There are many courses and tutorials available online to help you learn JavaScript.

With Dart, however, things are very different. Learning Dart can be intimidating for beginners because it’s not as well known as JavaScript and there’s relatively little material to learn. But Google has gone to great lengths to help developers of other OOP languages make the transition to Dart seamless.

Type safety

This is one of the major differences between JavaScript and Dart. As an interpreted language, JavaScript supports dynamic typing and duck typing. A duck type is a type that determines whether an object is suitable for a particular purpose based on the existence of specific methods and properties rather than the type of the object itself. Javascript allows you to type any code, making it a non-type-safe language, resulting in errors only being found at run time.

In contrast, Dart supports loose and robust prototyping. As a compiled language, Dart is able to catch most errors during compilation, making it more type-safe than JavaScript.

Companies use

JavaScript has been used commercially, even in large projects, to build Web and cross-platform applications. React and React Native, the Web and cross-platform frameworks introduced by Facebook, use JavaScript and are used within Facebook. Airbnb, Slack, eBay and others use JavaScript.

Dart was born at Google, so it was widely used internally at first. Then, after introducing Flutter, big companies like Alibaba adopted Flutter and Dart to develop their cross-platform applications.

Compile Dart into JavaScript

Dart has two different JS compilers, and the Webdev tool selects the best compiler based on the use case. When developing the application, WebDev chooses DartDevc, which supports incremental compilation so you can quickly see the results of your edits. However, when building the application to deploy, WebDev chooses Dart2JS, which uses techniques like tree shaking to generate optimized code.

The Dart team is working to make Dart 2JS compiled code run faster than handwritten JS. While this may not be the case in all cases, we can expect some serious competition in the near future.

The pros and cons

JavaScript

Advantages:

  • JavaScript can be used for Web and mobile applications.
  • It can be used on both the front and back ends, so JavaScript can run on every device.
  • JavaScript has a large community and a great framework available online.
  • Light and flexible.
  • A great deal of learning material can be found.

Disadvantages:

  • Although JS has a large number of libraries, many of them are of poor quality and maintainability.
  • Errors are found only at run time.

Dart

Advantages:

  • Open source.
  • Backed by a big company, Google.
  • Type safe and compiled using JIT and AOT.
  • The backbone of Flutter.
  • Relatively faster in some cases

Disadvantages:

  • Relatively new to programmers.
  • Compared to JavaScript, the learning material is not extensive.

conclusion

Dart and JavaScript are ideal for developing a variety of applications. With their use in Flutter and React, React Native, I can see a bright future for both languages. Dart was chosen as the first language on your 2019 list with 223 votes in a poll conducted by Jaxenter. In addition, Dart (66.3 percent) ranked second only to JavaScript (66.8 percent) as the most popular programming language in 2019 in a Stack Overflow survey. Dart also ranks first in the “Github State of the Octoverse” fastest-growing language category.

As a new developer, I recommend starting with JavaScript and mastering its basics first. You don’t necessarily need to be a JS professional, but you need to know the basics. Once you’re done, you can turn into Dart and explore its waters. In this way, you can become acquainted with the two giants without a shadow of a doubt.


Source: blog.bitsrc.io, written by Mahdhi Rezvi, translated:

This article is first published in the wechat public number “front-end foreign language selection”, attention is to send a gift package, you can save a lot of money!