is it ok to use succinct arrow function syntax if I'm not returning a value? [closed]










0















Let's say I have the function pageScroller that doesn't return any value.
Given that the succinct ES6 arrow function syntax implicitly returns the value, is it correct still ok to use it without block around?



const goToPage = pageNumber => pageScroller(pageNumber)


or I should always prefer the explicit block instead? I.e.:



const goToPage = pageNumber => 
pageScroller(pageNumber)



My only worrying is that people reading the code can expect that pageScroller returns a value. What do you think?










share|improve this question















closed as primarily opinion-based by charlietfl, Quentin, Mark Meyer, Liam, Patrick Roberts Nov 14 '18 at 16:28


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.













  • 5





    Why not const goToPage = pageScroller; ? But actually thats quite opinion based.

    – Jonas Wilms
    Nov 14 '18 at 16:18






  • 1





    Technically every JavaScript function returns a value. In most cases it's undefined.

    – amphetamachine
    Nov 14 '18 at 16:19











  • This is very much a matter of opinion

    – Quentin
    Nov 14 '18 at 16:19
















0















Let's say I have the function pageScroller that doesn't return any value.
Given that the succinct ES6 arrow function syntax implicitly returns the value, is it correct still ok to use it without block around?



const goToPage = pageNumber => pageScroller(pageNumber)


or I should always prefer the explicit block instead? I.e.:



const goToPage = pageNumber => 
pageScroller(pageNumber)



My only worrying is that people reading the code can expect that pageScroller returns a value. What do you think?










share|improve this question















closed as primarily opinion-based by charlietfl, Quentin, Mark Meyer, Liam, Patrick Roberts Nov 14 '18 at 16:28


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.













  • 5





    Why not const goToPage = pageScroller; ? But actually thats quite opinion based.

    – Jonas Wilms
    Nov 14 '18 at 16:18






  • 1





    Technically every JavaScript function returns a value. In most cases it's undefined.

    – amphetamachine
    Nov 14 '18 at 16:19











  • This is very much a matter of opinion

    – Quentin
    Nov 14 '18 at 16:19














0












0








0








Let's say I have the function pageScroller that doesn't return any value.
Given that the succinct ES6 arrow function syntax implicitly returns the value, is it correct still ok to use it without block around?



const goToPage = pageNumber => pageScroller(pageNumber)


or I should always prefer the explicit block instead? I.e.:



const goToPage = pageNumber => 
pageScroller(pageNumber)



My only worrying is that people reading the code can expect that pageScroller returns a value. What do you think?










share|improve this question
















Let's say I have the function pageScroller that doesn't return any value.
Given that the succinct ES6 arrow function syntax implicitly returns the value, is it correct still ok to use it without block around?



const goToPage = pageNumber => pageScroller(pageNumber)


or I should always prefer the explicit block instead? I.e.:



const goToPage = pageNumber => 
pageScroller(pageNumber)



My only worrying is that people reading the code can expect that pageScroller returns a value. What do you think?







javascript ecmascript-6 arrow-functions code-readability






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 16:20









Patrick Roberts

20.3k33576




20.3k33576










asked Nov 14 '18 at 16:16









Valerio LeoValerio Leo

31




31




closed as primarily opinion-based by charlietfl, Quentin, Mark Meyer, Liam, Patrick Roberts Nov 14 '18 at 16:28


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as primarily opinion-based by charlietfl, Quentin, Mark Meyer, Liam, Patrick Roberts Nov 14 '18 at 16:28


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 5





    Why not const goToPage = pageScroller; ? But actually thats quite opinion based.

    – Jonas Wilms
    Nov 14 '18 at 16:18






  • 1





    Technically every JavaScript function returns a value. In most cases it's undefined.

    – amphetamachine
    Nov 14 '18 at 16:19











  • This is very much a matter of opinion

    – Quentin
    Nov 14 '18 at 16:19













  • 5





    Why not const goToPage = pageScroller; ? But actually thats quite opinion based.

    – Jonas Wilms
    Nov 14 '18 at 16:18






  • 1





    Technically every JavaScript function returns a value. In most cases it's undefined.

    – amphetamachine
    Nov 14 '18 at 16:19











  • This is very much a matter of opinion

    – Quentin
    Nov 14 '18 at 16:19








5




5





Why not const goToPage = pageScroller; ? But actually thats quite opinion based.

– Jonas Wilms
Nov 14 '18 at 16:18





Why not const goToPage = pageScroller; ? But actually thats quite opinion based.

– Jonas Wilms
Nov 14 '18 at 16:18




1




1





Technically every JavaScript function returns a value. In most cases it's undefined.

– amphetamachine
Nov 14 '18 at 16:19





Technically every JavaScript function returns a value. In most cases it's undefined.

– amphetamachine
Nov 14 '18 at 16:19













This is very much a matter of opinion

– Quentin
Nov 14 '18 at 16:19






This is very much a matter of opinion

– Quentin
Nov 14 '18 at 16:19













1 Answer
1






active

oldest

votes


















0














This is largely opinion based but you're not wrong to want to be cautious about other people thinking you might be trying to assign a value.



I'd recommend looking at the code again after a couple weeks of working with something else and see if you recognize what it's doing immediately. Also, think about if the goToPage const will ever need to do anything other than call the pageScroller. If there's any chance it would, you might be better off calling the explicit block. If there isn't, maybe see if you can just call pageScroller directly instead of using a const?






share|improve this answer





























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This is largely opinion based but you're not wrong to want to be cautious about other people thinking you might be trying to assign a value.



    I'd recommend looking at the code again after a couple weeks of working with something else and see if you recognize what it's doing immediately. Also, think about if the goToPage const will ever need to do anything other than call the pageScroller. If there's any chance it would, you might be better off calling the explicit block. If there isn't, maybe see if you can just call pageScroller directly instead of using a const?






    share|improve this answer



























      0














      This is largely opinion based but you're not wrong to want to be cautious about other people thinking you might be trying to assign a value.



      I'd recommend looking at the code again after a couple weeks of working with something else and see if you recognize what it's doing immediately. Also, think about if the goToPage const will ever need to do anything other than call the pageScroller. If there's any chance it would, you might be better off calling the explicit block. If there isn't, maybe see if you can just call pageScroller directly instead of using a const?






      share|improve this answer

























        0












        0








        0







        This is largely opinion based but you're not wrong to want to be cautious about other people thinking you might be trying to assign a value.



        I'd recommend looking at the code again after a couple weeks of working with something else and see if you recognize what it's doing immediately. Also, think about if the goToPage const will ever need to do anything other than call the pageScroller. If there's any chance it would, you might be better off calling the explicit block. If there isn't, maybe see if you can just call pageScroller directly instead of using a const?






        share|improve this answer













        This is largely opinion based but you're not wrong to want to be cautious about other people thinking you might be trying to assign a value.



        I'd recommend looking at the code again after a couple weeks of working with something else and see if you recognize what it's doing immediately. Also, think about if the goToPage const will ever need to do anything other than call the pageScroller. If there's any chance it would, you might be better off calling the explicit block. If there isn't, maybe see if you can just call pageScroller directly instead of using a const?







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 16:28









        Thorin JacobsThorin Jacobs

        27029




        27029















            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto