Search code examples
javascriptstring-concatenation

Why concatenate simple strings instead writing it directly?


Today I found a code snipped which has multiple strings concatenate together with +. But why separate a string like '<script ...? Has it something to do with bots or do some developers try do make it harder to find some specific code?

document.write('<scr'+'ipt type="text/javascript" s'+'rc="' + RecaptchaState.server + 'js/recaptcha.js"></scr'+'ipt>');

I really do not see any benefit of doing this.


Solution

  • It's because the html parser sees </script>, even inside javascript, it will treat it as the closing tag for the containing script. Breaking it up makes the HTML parser happy