Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 10
Html comment inside the script tag! PLEASE HELP.....
Can I use html comment inside the script tag (Internal JavaScript) ? If yes then why? and What is the PURPOSE To use it inside the script tag 🙄?
41 Answers
+ 5
This is quite interesting! I didn’t try using comment inside the script tag. I thought it will produce an error. But it didn’t. However, you shouldn’t write using 'html comment style'. Follow the javascript instructions to write a comment.
+ 5
Well I don't know this much about web designing I'm learning but comments are not displayed as we know that and JavaScript comments are // &/*....*/ So there's no logic according to me place html comments inside the script tag (i.e. internal JavaScript)😐
+ 5
Konika, I totally agree with you and also don't recommend to use it!
+ 4
Well according to me it doesn't works but our teacher give all the class some assignments of JavaScript and most of the students use internal JavaScript and they use
Like this as shown below:👇🏻👇🏻
<Script>
<!--
............
Content
................
//-->
Also I asked to my teacher and She said it is mandatory 🙄😒also to my classmate he said that if browser does not support JavaScript then they will took it as a comment 🙄
Also my teacher send me the piks from the book of INTERNET APPLICATIONS by ANSHUMAN SHARMA
There's a syntax of JavaScript like:-👇🏻
<Script>
<!--
//JavaScript code
//-->
</Script>
😒😒 I'm getting totally confused and unable to understand this 🤔
Also in that book every internal JavaScript code contains this syntax 😐😑😑
+ 4
Konika Actually I guess as <script> tag is part of HTML, the html comment inside this tag, works. Just like when you put a comment inside <div> tag, <p> tag etc. For example :
<div>
<!-- HTML comment and it works -->
</div>
Again,
<script>
<!-- HTML comment and it works too -->
</script>
I think it'll help you clear your doubt!
+ 4
But last night I searched alot and I saw even in the new HTML they also use this in some scripts something looking like this
<script>
<!--
JavaScript
Code
//--> OR -->
</Script>
+ 4
I know yr
+ 4
I also preferred this type but when I saw that I was like wth is this
+ 4
It is not a bad idea. In fact it was the only hack in those days to avoid browsers that don't support javascript from printing all the program in the web page. Since javascript will not raise an error and script-supported browsers will still execute your javascript
But now you don't need that. Just put your script tag in your <head> or place it in an external file if you want to put your <script> tag in <body>
+ 4
Actually the fact that script tag is html code is not the reason for this.
For example try this:
<script>
<!-- lol()
Hello();
-->
</script>
Output: Error Hello is not a function.
<!-- and --> are official SINGLE LINE comments in WEB ECMAScript spec only.
They are part of JS(for compatibility) not of HTML.
--> This is a single line comment.
+ 4
If it's a script tag.
The best thing you should do is add a JavaScript comment
Not an HTML
Coz even if it's internal , you are still gonna write JavaScript in it which is very different from the html syntax
So even if you add an HTML comment it'll be like confusing
And firstly don't use internal js
External is much better
+ 3
???
+ 3
Wth is this😑😑😐😐😒😒
+ 3
I already raised man
+ 3
Well in the book it's given as JavaScript syntax 😒
+ 3
<script>
<!--
//JavaScript code
//-->
</Script>
+ 3
This maner is wrong
+ 3
I know but my teacher said it is mandatory
+ 3
I did it already man but don't have any effect on the output
+ 3
Like if I'm putting that as a comment then it will definitely take it as a comment but doesn't happen like this what I think