"An external JavaScript cannot contain script tag" what does it mean? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

"An external JavaScript cannot contain script tag" what does it mean?

Does it mean that the JavaScript code can be written in HTML without using script tag if this will we used as external .js file??

19th Feb 2019, 5:40 AM
Kunal Acharya
Kunal Acharya - avatar
4 Answers
+ 5
In the.js file you do not need to start by writing <script> as though it was part of a HTML code.
19th Feb 2019, 5:55 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
I would explain this with an example. Suppose you had written some js in an HTML file. <Head> ..... <Script> Alert('Js is working'); </Script> ... Now if you have a lot of JavaScript then it is better to separate html and Js in different files. 1. Create a file with .js extension. Eg: test.js 2. Cut everything from inside of script tag, from the HTML file. And remove the script tag from HTML file. 3. Paste into the test.js and save. 4. Link the js file from the HTML <Script SRC="test.js"></script> assuming html and Js file are in the same directory. 5. Done. Script tag is an html tag and JavaScript doesn't understand it, Script tag is used in an html file to write JavaScript. When you write your JavaScript in a separate file script tag is not required in the js file.
19th Feb 2019, 6:13 AM
Bk Str
Bk Str - avatar
+ 1
Thanks
19th Feb 2019, 6:13 PM
Kunal Acharya
Kunal Acharya - avatar
+ 1
Thanks
22nd Feb 2019, 5:16 AM
Huzaifa usman
Huzaifa usman - avatar