Friday, 27 September 2013

Javascript string concatenation with a function behaves strange

Javascript string concatenation with a function behaves strange

I am trying to concate something like "string"+function(){return "string"}
in document.write() in javascript.
For example:
document.write("I don't know "+function(){if(true){return "why does it
concat?"}});
And it prints something like this bellow (see it running in the jsfiddle:
http://jsfiddle.net/sadaf2605/3AuLD/):
I don't know function (){if(true){return "why does it concat?"}}
I know I have written something very very silly but still why should it
print something like this? I am curious about that!

No comments:

Post a Comment