Readable code is worth a hundred comments.
function square(n) {
return n * n;
}is better than
// Function to square a number.
eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('2 1(0){3 0*0}',4,4,'n|square|function|return'.split('|'),0,{}))
True, but sometimes that's unavoidable. (Like in onClick attributes. I have trouble with functions. :))
I didn't point out that multi-line comments (which are 'closed') allow you to do this:
/*This is a comment */ this(is,some,code);
i just gotta laugh at the second example! LOL
Are you referring to:
<!-- this is a multi-
line comment in HTML -->
<xsl:comment>this is a comment in XSLT</xsl:comment>
<xsl:comment>this is a multi-
line comment in XSLT</xsl:comment>
// Function to square a number.
eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('2 1(0){3 0*0}',4,4,'n|square|function|return'.split('|'),0,{}))
I'm assuming
// Function to square a number.
eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('2 1(0){3 0*0}',4,4,'n|square|function|return'.split('|'),0,{})).
LOL, I would go with:
function square(x) {
var squared = 8*8;
return squared;
}
document.write('Square the number: <input name="textfield" type="text" id="textfield" size="5" onClick="square(document.getElementById('textfield').value);">');