Curly braces and arrow funcs

(apologies it’s late here and i was struggling a while…)

can we never use braces in an arrow func?
if i try this with {…} (as is shown i thought in MDN?) it just returns false always, but after many wall head-buttings it works fine without curlies!

myStr.every((val, i)=> val == myStr[myStr.length-i-1] )
not work:
myStr.every((val, i)=> {val == myStr[myStr.length-i-1] )}

1 Like

You can use curly braces to define a function block, but when you do that you need an explicit return statement.

myStr.every((val, i)=> val == myStr[myStr.length-i-1] )

is exactly the same as

myStr.every((val, i)=> { 
    return val == myStr[myStr.length-i-1];
})
2 Likes

thanks.
it’s so easy to forget stuff you already learnt.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.