+ 3

why do programmers use thier js code in script tag in html as well as in js section.

I have a doubt why don't programmers use their whole javascript code in just script tag or in js section. (I've started learning JavaScript)

3rd Apr 2018, 1:33 PM
Robin Singh
Robin Singh - avatar
5 Respostas
+ 10
Functionality-wise it doesn't really matter unless you need the JavaScript to run in a specific order. Here's an example of the execution order of SoloLearn's Code Playground:- https://code.sololearn.com/WXe61FrE4YD4/?ref=app
3rd Apr 2018, 3:14 PM
Zephyr Koo
Zephyr Koo - avatar
+ 5
In SoloLearn it's just small casual codes mostly but this directory structure is what I see common on many client side codes |_ Main directory |_ index.html |_ CSS folder |_ master.css |_ js folder |_ index.js
3rd Apr 2018, 2:38 PM
Morpheus
Morpheus - avatar
+ 3
Also, by keeping your files separate, you also make the entire thing a lot more modular than if you throw it all inside of the same file. Imagine that you start another project and you had code that could be reused. Would you want to dissect your HTML and obtain the code so you can copy/paste it over, or would you rather have a file that it's already isolated inside of which you can simply link to your new project? When you can make and keep things modular, it's often beneficial.
3rd Apr 2018, 2:30 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 2
Just bad habit because sometimes it's easier to do something where you're already at than to go to other files. We'll just call it lazy. :D From my experience it's better and tidier to keep your HTML/JS/CSS separate from one another and then just link them into your HTML.
3rd Apr 2018, 1:43 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 1
sometimes render blocking parts of scripts are put inside html
3rd Apr 2018, 2:44 PM
wenz
wenz - avatar