The second example looks a lot nicer to me.
Note 1: you can use const instead of let in your second example because you do not transform the object anywhere in your function.
Note 2: second example will return undefined instead of '' if the key in the object does not exist. I think you'd handle that as well.
''
*because you do not reassign the reference.
You can transform an object variable declared with const.
const
Thanks for pointing out the difference between let and const, I'll keep that in mind.
let
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The second example looks a lot nicer to me.
Note 1: you can use const instead of let in your second example because you do not transform the object anywhere in your function.
Note 2: second example will return undefined instead of
''
if the key in the object does not exist. I think you'd handle that as well.*because you do not reassign the reference.
You can transform an object variable declared with
const
.Thanks for pointing out the difference between
let
andconst
, I'll keep that in mind.