Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.
2nd May 2020, 8:30 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 5
Konika, I totally agree with you and also don't recommend to use it!
2nd May 2020, 8:47 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 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!
2nd May 2020, 8:43 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 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>
3rd May 2020, 9:06 PM
Ore
Ore - avatar
+ 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.
3rd May 2020, 11:49 PM
Kevin ★
+ 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
4th May 2020, 9:06 AM
xym
xym - avatar
+ 3
This maner is wrong
3rd May 2020, 7:56 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
+ 3
Don't need to give comment inside the script.
3rd May 2020, 9:19 AM
Mahfazzalin Shawon Reza
Mahfazzalin Shawon Reza - avatar
+ 3
Yes, you can use it. For example: <script> <!-- html comment goes here --> </script>
4th May 2020, 12:53 AM
Adegoke Adewale Saheed
Adegoke Adewale Saheed - avatar
+ 2
In script tag we use // for single line comment /* used for multiple line comment */
3rd May 2020, 8:14 AM
Tanveer Ahmad
Tanveer Ahmad - avatar
+ 1
If you like i can cake test for you on my account then i send you the link
3rd May 2020, 8:00 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
+ 1
This syntax is wrong forget it please
3rd May 2020, 8:17 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
+ 1
But I used this way for comment // single line /* multiple line */
3rd May 2020, 8:18 AM
Tanveer Ahmad
Tanveer Ahmad - avatar
+ 1
You can't use HTML comment inside the script tag. I suggest that you should try using it then you would notice that the HTML comment won't work inside the script tag
3rd May 2020, 11:02 AM
ℤ𝕚𝕔𝕔𝕠
ℤ𝕚𝕔𝕔𝕠 - avatar
+ 1
people how to make the buttons in this code be like in the mobile version of the browser? On the mobile, everything is as it should, but on the computer, everything is bad! https://code.sololearn.com/W17NGHhIZwEX/?ref=app
3rd May 2020, 4:11 PM
PS&Snow
PS&Snow - avatar
0
It's impossible Either you make js comments or html out of the script tag
3rd May 2020, 7:49 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
0
If you make javascript in thoses tag you will look at syntax error
3rd May 2020, 7:57 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
0
What effect do you expect from your tests?
3rd May 2020, 8:02 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
0
When you put some thing in the script tag this thing is supposed to be a script and each script language has his own conment manner so inside the script tag Forget that you coding in HTML , you have to use the javascript ecpression For more contact me
3rd May 2020, 8:08 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
0
This beast is from ancient times. In the dark ages, there were browsers who didn't understand script tags; they're long gone now but the habit remained. What you see is a trick to avoid misinterpretations. Smart browsers will say: "OK this is a script tag, let's execute, don't mind the leading <!-- string." Dumb browsers: "OK I don't know this tag called script, but inside it's just a comment so I'm gonna skip it. Yep, here's where the comment ends, here's where the weird tag ends, everything's fine." In 2005 this was important, today it's absolutely not. Your teachers learned this way and pass it on; forget about it, in 2022 literally every toaster and frying pan knows what a script tag is and how to deal with it.
2nd Nov 2022, 10:34 AM
Denes Kellner
Denes Kellner - avatar