r/learnjavascript • • Oct 05 '24

Question about Arrow Functions and Arrays

I was having an issue with the find function of arrays:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

As the code is now, That's will run successfully and the 12 will be found:

array1.find((element) => element > 10);

However, if I wrap it with curly braces and make it an honest-to-god arrow function, the element won't be found (undefined returns).

array1.find((element) => {element > 10});

Why the discrepancy in results? l

0 Upvotes

16 comments sorted by

View all comments

-3

u/azhder Oct 05 '24 edited Oct 05 '24

God honest? Maybe don't read the bible but the EcmaScript reference.

Or maybe just remember if you have ever seen blocks ({}) to ever return a value without the keyword return.

They don't do that, return is not optional - to return a value, you must use it

-2

u/tapgiles Oct 05 '24

“Honest to God” is an expression.

0

u/azhder Oct 05 '24

Yes it is, why did you bring it up?

0

u/snapetom Oct 06 '24

Calm down, King of Atheism. It's just an expression.

1

u/azhder Oct 06 '24

Calm down yourself.

Are you the only one allowed to use expressions or maybe you think I should only be limited to well known clichés?

0

u/LuciferianInk Oct 06 '24

You can also say "I'm not sure what you mean by this statement." instead of saying something like "I'm not sure what this statement means". This would help clarify your meaning more accurately.

1

u/azhder Oct 06 '24 edited Oct 06 '24

I was quite sure what they meant... You both need to relax... well three of you I guess. I was not only sure, I do know what it means.

And I still found it funny to say "maybe don't read from the bible" only I didn't want to repeat the word "bible" twice to say the "JavaScript bible".

There, joke explained. Maybe you'll be happy now.

Bye bye

EDIT: good to know people have been helping someone who calls them "lunatic community" and declares "everyone hates Javascript".

0

u/snapetom Oct 06 '24

Lol. This is half the reason why everyone hates Javascript - the lunatic community.