DEV Community

Discussion on: How to clone a portion of an object using the power of IIFE, arrow functions, destructuring assignment and property shorthands.

Collapse
 
briancodes profile image
Brian • Edited

Does lastName value get assigned to const _? I take it the _ is a convention for unused variables, seen it used before for arguments that are not referenced (I think)

Collapse
 
andrejnaumovski profile image
Andrej Naumovski

Yup, it's mostly an unwritten rule adopted as a convention for variables that must be there but aren't going to be referenced anywhere. Similarly if you want to use .map() but only need the index, not the element itself for some weird reason:

const newArr = arr.map((_, idx) => { /* do something only with idx */ });