Home > Web Front-end > JS Tutorial > body text

The difference between JavaScript and Dart

Guanhui
Release: 2020-06-01 09:11:54
forward
3604 people have browsed it

The difference between JavaScript and Dart

#What is JavaScript?

JavaScript is often referred to as a browser scripting language, but it has also been extended to many server-side and mobile application development environments. 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?

Dart is a language specifically designed by Google for client-side optimization for fast applications on various 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 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");
}
Copy after login

Javascript

console.log("Hello World")
Copy after login

Comparison of JavaScript and Dart

1. Popularity

JavaScript is actually everywhere, and there are almost no devices that do 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.

2. 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.

3. 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.

4. 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.

The difference between JavaScript and Dart

Compile Dart to JavaScript

There are two different JS compilers for Dart , the Webdev tool selects the best compiler based on the use case. 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 in 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.

Recommended tutorial: "

JS Tutorial"

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

Related labels:
js
source:juejin.im
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!