Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
brandonlind2
7,823 PointsWhat is the purpose of the type attribute when linking javascript
What is the purpose of the type and charset attrubtes, it seems to work perfectly fine without them.
<script src='main.js'></script>
<script scr='main.js' type='text/javascript' charset='utf-8'></script>
1 Answer
Ana Enríquez
8,977 PointsWhat Patryk is saying is right, it is not required for javascript, but it is a common good practice to do it because the browser has the information without checking it and helps to make your code more legible.
Patryk Bernasiewicz
Courses Plus Student 10,281 PointsPatryk Bernasiewicz
Courses Plus Student 10,281 PointsIt works perfectly without the type="text/javascript" declaration, because it's the default type that is assigned to the script tag.
You don't need to specify the type of your scripts, but for some reason it's became a common practice (or probably a habit) to just do.