How to import jQuery using ES6 syntax with JavaScript?

Sometimes, we want to import jQuery using ES6 syntax with JavaScript.

In this article, we’ll look at how to import jQuery using ES6 syntax with JavaScript.

How to import jQuery using ES6 syntax with JavaScript?

To import jQuery using ES6 syntax with JavaScript, we can use import.

For instance, we write

import { $, jQuery } from "jquery";

window.$ = $;
window.jQuery = jQuery;

to import $ and jQuery from the jquery module.

And then we assign $ and jQuery to properties of window with

window.$ = $;
window.jQuery = jQuery;

to make them global.

Conclusion

To import jQuery using ES6 syntax with JavaScript, we can use import.