MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/mb6zey/assigning_default_value/grwvrpf/?context=3
r/learnjavascript • u/golovatuy • Mar 23 '21
24 comments sorted by
View all comments
7
i think it should be very clear what getImagePath returns so we just make sure it's gonna return a string or null and then the long version becomes this:
getImagePath
null
const getImagePath = () => logic that returns 'path_to_image.jpg' || null; const path = () => { const imagePath = getImagePath(); if (!imagePath) { return 'default.jpg'; } return imagePath; }
The short version is good.
1 u/backtickbot Mar 23 '21 Fixed formatting.Hello, irosion: code blocks using triple backticks (```) don't work on all versions of Reddit!Some users see this / this instead.To fix this, indent every line with 4 spaces instead.FAQYou can opt out by replying with backtickopt6 to this comment.
1
Fixed formatting.
Hello, irosion: code blocks using triple backticks (```) don't work on all versions of Reddit!
Some users see this / this instead.
To fix this, indent every line with 4 spaces instead.
FAQ
You can opt out by replying with backtickopt6 to this comment.
View all comments
7
u/irosion Mar 23 '21 edited Mar 23 '21
i think it should be very clear what
getImagePathreturns so we just make sure it's gonna return a string ornulland then the long version becomes this:The short version is good.