import and export modules are not working!? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

import and export modules are not working!?

I am trying to use the import and export feature of js. Here are my files and codes ----------------------------------------------- module.js var x =10; export {x} export.js import x from './module.js' alert(x);

11th Mar 2020, 5:54 AM
Saurav Kumar
Saurav Kumar - avatar
3 Answers
+ 2
{x} is equivalent to {x:10} since x=10 Try alert(x.x); you would get a value of 10
11th Mar 2020, 5:58 AM
Calviղ
Calviղ - avatar
0
Yes..also how to import those modules in a normal HTML file. I have tried to import by writing it as the first statement. But there's an error as ' import declaration may not appear at top level of a module'. One more question : do I need to include the file of js using script src .. or it will work just by import?
11th Mar 2020, 6:04 AM
Saurav Kumar
Saurav Kumar - avatar
0
Move all import declarations to top of the lines.
11th Mar 2020, 6:12 AM
Calviղ
Calviղ - avatar