As far as I understood, using //
to comment on a line and /*...*/
was the same, with the difference that the second spanned more than one line if necessary.
There is SOME difference between doing
// var a = 'teste'
and
/* var a = 'teste' */
?
I asked because I came across a strange case, where I was discussing problem code inside a template string (which created a script tag with a syntax error code inside it) and as I commented on the problem line using /* */
I did not get a syntax error, but when I commented on the same line with //
, it gave me a syntax error when running.
Here is the code where I had the problem:
$('#dadosBeneficiario').html('
<script type="application/javascript">
function dropDown(node) {
var drop = $(node).next();
drop.slideToggle('slow');
}
function toggleObs(botao) {
var campo = $(botao).prev();
if (campo.val() !== '') {
if($('#descricaoOpcional').val() !== '') {
/* $('#descricaoOpcional').val($('#descricaoOpcional').val() + "\n______________________________________________________\n" + campo.val()); */
$(botao).hide();
} else {
$('#descricaoOpcional').val($('#descricaoOpcional').val() + campo.val());
$(botao).hide();
}
} else if ($(botao).val() === "Salvar") {
return;
}
campo.toggle('fast');
$(botao).val('Salvar');
}
</script>');
Commenting the line in this way, the code ignored the line and ran. But when commenting with double slash, I got syntax error:
// $('#descricaoOpcional').val($('#descricaoOpcional').val() + "\n______________________________________________________\n" + campo.val());
Why did this happen?