In this answer here, the OP's issue is syntactically incorrect code:
https://stackoverflow.com/a/52009987/1068446
So I've reproduced the error, in a simplified output:
function foo(x) {
return x%2 ===0; // x is an even number;
}
if (function foo(2)) {
console.log("we got here");
}
However, the error message isn't particularly meaningful:
{
"message": "Uncaught SyntaxError: Unexpected number",
"filename": "https://stacksnippets.net/js",
"lineno": 17,
"colno": 18
}
There is no line 17 in this code.
If I run this code with Node.js on my own machine, I get:
davidj@davidj-laptop:~/git-workspace/dsandbox$ node syntax.js
/home/davidj/git-workspace/dsandbox/syntax.js:5
if (function foo(2)) {
^
SyntaxError: Unexpected number
at new Script (vm.js:74:7)
This is a more useful error. The error points correctly to the line of the syntax error.
lineno
does not correspond to the line number users see in the editor (2) The embedded snippet's error does not print the actual line content (nor the character) at which the error occurs. A fix for either would be useful.Boolean(function abc() {})
which is not a syntax error, whereas you are responding with whyBoolean(function abc())
is incorrect.<body>
. So the line-no is actually correct, even if misleading. To fix it would require to know in which<script>
tag the code the error thrown in was, because you can insert<script>
tags in the HTML part too. And to do this is not a trivial task. Or, they would have to run this script as an external script, but this would mean from a blob URI and hence yet an other thing to include in every snippet...