Questions And Answers

More Tutorials

Dart JavaScript interoperability


Dart-JavaScript interoperability lets us run JavaScript code from our Dart programs. The interoperability is achieved by using the js library to create Dart stubs. These stubs describe the interface we'd like to have with the underlying JavaScript code. At runtime calling the Dart stub will invoke the JavaScript code.


Calling a global function

Suppose we'd like to invoke the JavaScript function JSON.stringify which receives an object, encodes it into a JSON string and returns it.

All we'd have to do is write the function signature, mark it as external and annotate it with the @JS annotation:

external String stringify(obj);

The @JS annotation will be used from here on out to mark Dart classes that we'd like to use in JavaScript as well.


In this page (written and validated by ) you learned about Dart JavaScript interoperability . What's Next? If you are interested in completing Dart tutorial, your next topic will be learning about: Dart Wrapping JavaScript classes and namespaces.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.