Jump to content

[SOLVED] Why do people leave comments in javascript code?


pkedpker

Recommended Posts

Are those people just bad JavaScript programmers or is it a trick to get other browsers with bad JavaScript parsing to make it work?

 

here is a example

 


<script language="JavaScript">
<!--
function setsmiley(what){
tmp=document.getElementById("mytext");
    tmp.value = tmp.value+" "+what+" ";
    tmp.focus();
}
//-->
</script>

 

why the hell did he leave <!-- when --> is commented out anyways its pure stupidity from my side.

 

Found this kind of error on google ads as well! had to remove the <!-- and //--> to save a few bytes!

 

but is there any trick to this? leaving them in I mean

The point of it is back in the day when javascript was new enough that there were browsers that didn't know what to do with it, it was a hack to keep js from being displayed as plain text, if the browser didn't support it.  So basically it's a backwards compatibility thing.  Why people are still doing it I have no idea, as it's been a long time since virtually every single browser out there at least recognizes javascript. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.