The return That Returns Nothing
luljs still worksPut the value on the line after return and the function hands back undefined.
In 2026: Still happens. JavaScript inserts a semicolon at a line break when the code so far is a complete statement, and return on its own is complete. So return followed by a newline returns undefined, and the value on the next line never runs. This is exactly why the opening brace of a returned object must sit on the same line as return.
Where it came from: Automatic semicolon insertion. Douglas Crockford made it a headline rule in JavaScript: The Good Parts, 2008: brace on the same line as return. MDN ↗
<script>
function total() {
return
42;
}
document.write('<p><code>return</code>, newline, then <code>42</code> gives <b>' + total() + '</b></p>');
document.write('<p>A semicolon is inserted after <code>return</code>, so the <code>42</code> is dead code.</p>');
</script>