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

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.