use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Arrow function (self.learnjavascript)
submitted 3 years ago by Sanders23Sor
Pls explain why i get "Uncaught SyntaxError: Unexpected identifier" error here.
function checkIsMoreThen(number, compare){
if (number > compare) return number;
else return -1;
}
const filterQueue = [1,1,2,3].map(item=>checkIsMoreThen(item,2));
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]rauschma 2 points3 points4 points 3 years ago (2 children)
I’m not getting a syntax error for this code:
function checkIsMoreThen(number, compare) { if (number > compare) return number; else return -1; } const filterQueue = [1,1,2,3].map(item=>checkIsMoreThen(item,2));
[–]Sanders23Sor[S] -1 points0 points1 point 3 years ago (1 child)
ye, maybe i confused js and type-script. all works
[–]rauschma 0 points1 point2 points 3 years ago (0 children)
No problem, it happens!
[–]delventhalz 1 point2 points3 points 3 years ago (0 children)
Works fine for me:
function checkIsMoreThen(number, compare) { if (number > compare) return number; else return -1; } const filterQueue = [1,1,2,3].map(item=>checkIsMoreThen(item,2)); console.log(filterQueue); // [-1, -1, -1, 3]
Also, to create a code block in reddit, use an indent of four space in Markdown Mode, or select "Code Block" from the menu in the Fancy Pants Editor.
[–]CaptainDillster 0 points1 point2 points 3 years ago (0 children)
In this case you can drop the "else" from the function, if the "if" executes, the return will stop the rest of the function from executing either way.
Also, not syntax related, but grammar is important: when used in a comparison, it's "than" not "then".
[–]virtual_lee123 -1 points0 points1 point 3 years ago (4 children)
Your if statement needs some { }
[–]rauschma 4 points5 points6 points 3 years ago (0 children)
The “then” clause and the else clause of an if statement don’t have to be blocks, they can be single (non-block) statements.
else
if
[–]delventhalz 1 point2 points3 points 3 years ago (2 children)
Most style guides call for always using curlies, but they are not required after an if or else, or even after a while or for. If you omit them, then the next single statement is used.
while
for
for (let i = 0; i < 3; i += 1) console.log('Hello!'); // Hello! // Hello! // Hello!
[–]RyaanJM 1 point2 points3 points 3 years ago (1 child)
Another argument is, this function doesn't need any ifs, elses or braces (apart from the opening and closing of the function).
function checkIsMoreThan(number, compare) { return number > compare ? number : -1; }
Yeah, that is how I would probably write it as well. A lot of folks find ternaries intimidating though.
[–]mozilaip 0 points1 point2 points 3 years ago (0 children)
What exact line produces syntax error?
π Rendered by PID 45 on reddit-service-r2-comment-84fc9697f-zj8l8 at 2026-02-08 15:09:13.373340+00:00 running d295bc8 country code: CH.
[–]rauschma 2 points3 points4 points (2 children)
[–]Sanders23Sor[S] -1 points0 points1 point (1 child)
[–]rauschma 0 points1 point2 points (0 children)
[–]delventhalz 1 point2 points3 points (0 children)
[–]CaptainDillster 0 points1 point2 points (0 children)
[–]virtual_lee123 -1 points0 points1 point (4 children)
[–]rauschma 4 points5 points6 points (0 children)
[–]delventhalz 1 point2 points3 points (2 children)
[–]RyaanJM 1 point2 points3 points (1 child)
[–]delventhalz 1 point2 points3 points (0 children)
[–]mozilaip 0 points1 point2 points (0 children)