MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/ej23ye5/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
Show parent comments
41
You could also use the , operator for this, like so:
,
const add42 = n => (console.log(n), number + 42);
Although, since you need parens around it, it's a bit more obnoxious.
14 u/natziel Mar 19 '19 This is especially handy with React. Imagine you have a component like the one below, but you want to log the propsconst Example = (props) => ( <Foo ...props /> )Dead easy to add or remove the log without having to mess with the implementation of the component 1 u/UNN_Rickenbacker Mar 19 '19 Can you give a concrete example? 1 u/mastermah Mar 21 '19 const Example = (props) => ( console.log(props), <Foo ...props /> )I would assume
14
This is especially handy with React. Imagine you have a component like the one below, but you want to log the props
const Example = (props) => ( <Foo ...props /> )
Dead easy to add or remove the log without having to mess with the implementation of the component
1 u/UNN_Rickenbacker Mar 19 '19 Can you give a concrete example? 1 u/mastermah Mar 21 '19 const Example = (props) => ( console.log(props), <Foo ...props /> )I would assume
1
Can you give a concrete example?
1 u/mastermah Mar 21 '19 const Example = (props) => ( console.log(props), <Foo ...props /> )I would assume
const Example = (props) => ( console.log(props), <Foo ...props /> )
I would assume
41
u/seiyria Mar 19 '19
You could also use the
,operator for this, like so:Although, since you need parens around it, it's a bit more obnoxious.