is it ok to use succinct arrow function syntax if I'm not returning a value? [closed]
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
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.
add a comment |
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
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 notconst 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'sundefined
.
– amphetamachine
Nov 14 '18 at 16:19
This is very much a matter of opinion
– Quentin
Nov 14 '18 at 16:19
add a comment |
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
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
javascript ecmascript-6 arrow-functions code-readability
edited Nov 14 '18 at 16:20
Patrick Roberts
19.4k33475
19.4k33475
asked Nov 14 '18 at 16:16
Valerio 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 notconst 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'sundefined
.
– amphetamachine
Nov 14 '18 at 16:19
This is very much a matter of opinion
– Quentin
Nov 14 '18 at 16:19
add a comment |
5
Why notconst 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'sundefined
.
– 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
add a comment |
1 Answer
1
active
oldest
votes
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?
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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?
add a comment |
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?
add a comment |
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?
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?
answered Nov 14 '18 at 16:28
Thorin Jacobs
27019
27019
add a comment |
add a comment |
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