Reputation: 1651
So I am having this document:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
//executes when HTML-Document is loaded and DOM is ready
alert("document is ready");
});
$(window).on("load", function () {
//executes when HTML-Document is loaded and DOM is ready
alert("window is loaded");
});
</script>
</body>
</html>
Note the inline comments inside the 2 function calls.
Apparently these do NOT work and give me an error:
SyntaxError: missing } after function body[Weitere Informationen] index:1:297 note: { opened at line 1, column 37
However using a multiline comment /* */
is working just perfectly.
I`m assuming, that the single line comments dont work becuase somehow the javascript gets minified into one line.
Can sombody evaluate an how this is happening?
Where can you use single line comments and where not?
Or is it just generally a bad idea to use single line comments in js?
Upvotes: 0
Views: 1651
Reputation: 201
Because after minifying everything is just one line, a single line comment, which doesn't have an end-of-comment tag, doesn't work.
Upvotes: 2