Home  >  Article  >  Web Front-end  >  JavaScript vs Dart The difference and role between the two

JavaScript vs Dart The difference and role between the two

hzc
hzcforward
2020-06-17 10:08:202470browse

What is JavaScript?

JavaScript vs Dart The difference and role between the two

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

JavaScript has its own package managers such as NPM and Yarn. Even though JavaScript is now preferred and popular, it still has some mixed reviews in the programming community. Still, it’s safe to say that JavaScript’s popularity is unquestionable, as it contains nearly 2 million questions tagged on StackOverFlow.

What is Dart?

JavaScript vs Dart The difference and role between the two

Dart is a language specifically designed by Google to be client-side optimized for fast applications on various platforms. Google initially used it as an internal programming language to build web, server, and mobile applications. Although Dart has been around since 2011, it became popular after Google announced Flutter for cross-platform mobile app development. The only reason is that Flutter is completely 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 the Dart VM. Dart also has its own package manager called Pub.

Sample application using Dart and JavaScript

Dart.js

void main() {  
    print("Hello World");
}

Javascript

console.log("Hello World")

JavaScript with Dart Comparison

Popularity

JavaScript is virtually everywhere, and there is almost no device that does not run JavaScript. Currently, JavaScript is used to write web, mobile, and server-side code. JavaScript has been tagged in nearly 2 million questions on StackOverflow.

Due to its popularity, the JS ecosystem is huge and now, with the advent of Cloud Component Center, it even dominates the reusable component "market".

On the other hand, Dart is becoming more and more popular, but it is still far away from JavaScript. Before Google announced Flutter, Dart was nowhere to be found. Dart attracts developers who don't support JavaScript. Currently, Dart has nearly 30,000 questions tagged on StackOverFlow.

Learning Curve

It’s no secret that JavaScript can be quite tricky for beginners, especially when they have no background knowledge of programming concepts. But JavaScript is one of the main languages ​​taught in universities and bootcamps because it is one of the core of web development. In fact, HTML, CSS, and JavaScript are called the three musketeers of web development. There are many courses and tutorials online to help you learn JavaScript.

However, with Dart, the situation is very different. Learning Dart can be very intimidating for newbies because it is not as well-known as JavaScript and there is relatively little learning material. But Google goes to great lengths to help developers of other OOP languages ​​make a seamless transition to Dart.

Type Safety

This is one of the main differences between JavaScript and Dart. As an interpreted language, JavaScript supports dynamic typing and duck typing. Duck typing is a type that determines whether an object is suitable for a specific purpose based on the presence of specific methods and properties rather than the type of the object itself. Javascript allows any code to be typed, making it a non-type-safe language, causing errors to be discovered only at runtime.

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

Enterprise Usage

JavaScript is 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 internally at Facebook. Other companies like Airbnb, Slack, eBay, and others also use JavaScript.

Dart’s birthplace is Google, so in the beginning it was widely used internally. Then, after the introduction of Flutter, big companies like Alibaba adopted Flutter and Dart to develop their cross-platform applications.

JavaScript vs Dart The difference and role between the two

Compile Dart to JavaScript

There are two different JS compilers for Dart, Webdev tools choose based on use case Best compiler. When developing applications, webdev chooses dartdevc, which supports incremental compilation so you can quickly see the results of your edits. However, when it comes to building applications for deployment, webdev chooses dart2js, which uses techniques like tree shaking to generate optimized code.

The Dart team is working hard to make dart2js compiled code run faster than hand-written JS. While that won't be the case in every case, we can expect some serious competition in the near future.

Pros and Cons

JavaScript

Pros:

  • JavaScript can be used for Web and mobile applications.
  • It can be used on both frontend and backend, so JavaScript can run on every device.
  • JavaScript has a huge community and great frameworks available online.
  • Lightweight and flexible.
  • You can find a lot of learning materials.

Disadvantages:

  • Although there are a large number of libraries for JS, there are many libraries with poor quality and maintenance.
  • Errors are only found at runtime.

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:

  • Not for programmers The language is relatively new.
  • The learning material is not extensive compared to JavaScript.

Conclusion

Both 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. In a poll conducted by Jaxenter, Dart was voted the number one language on your 2019 list with 223 votes. Furthermore, in a survey conducted by Stack Overflow, Dart (66.3%) was second only to JavaScript (66.8%) as the most popular programming language in 2019. Dart also ranks first in the "Github State of the Octoverse" fastest-growing language category.

JavaScript vs Dart The difference and role between the two
JavaScript vs Dart The difference and role between the two
Credits: GitHub
#As a newbie developer, I recommend that you start with JavaScript and master 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 switch over to Dart and explore its waters. In this way, you can become familiar with these two giants to the letter.

Recommended tutorial: "

JS Tutorial"

The above is the detailed content of JavaScript vs Dart The difference and role between the two. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.cn. If there is any infringement, please contact admin@php.cn delete