How to use import?

how to use import in javascript?

You can import another javascript file in your project. As far as I know you can’t import javascript from other websites.

Happy coding!

~ RetroTechXYZ

@hackerbaby41 can you give some more context to your question?

If you mean how to use the import call inside of a file (as opposed to importing a project into glitch) I think import should work right out of the box in backend files. If you want to use it in frontend files, you’ll need to use a compiler, like babel.

This post should be helpful with babel –

If you’re trying to learn about using import in general (not just how to get it working with glitch) this might be a helpful resource! https://javascript.info/import-export

Let me know if any of this doesn’t make sense, or doesn’t answer your question!

One thing to note is that you don’t need to use babel to get import working in front-end Javascript—that comes built in with modules! (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). You’ll need something like Webpack set up if you want to import external libraries (from npm) in your front end code though.

1 Like

import function for running other javascript file from other file

Ah, thanks for the correction @nightpool!