Would you suggest to write the script in the same HTML file or link the HTML file to a JavaScript file? Why? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

Would you suggest to write the script in the same HTML file or link the HTML file to a JavaScript file? Why?

3rd Nov 2017, 4:39 PM
Pablo de Esesarte
Pablo de Esesarte - avatar
3 Antworten
+ 6
Keep your CSS, HTML, and JS scripts in their own files and separate. This makes your code cleaner and easier to read/maintain/change. When there are issues, it's much easier to go directly to the script file and make changes rather than having to poke around through a bunch of other code to get to it. If others end up working on it, or if you end up leaving it alone for awhile and coming back, it'll make it a lot easier to know what's going on and make necessary changes. Also, this approach is a lot more modular, so you can reuse your code in other projects more easily if it's already isolated into its own files.
3rd Nov 2017, 4:44 PM
AgentSmith
+ 2
Thanks a lot!
3rd Nov 2017, 5:36 PM
Pablo de Esesarte
Pablo de Esesarte - avatar
+ 1
Keeping the HTML, CSS, & JS files separately makes the code cleaner, easy to manage and edit each file more efficiently without much hectic effort to go through a lot of line of code, helping in maintainability & reusability in modular approach.
3rd Nov 2017, 10:47 PM
Muazzam Younus
Muazzam Younus - avatar