'Collecting' an Object Pre-ES2015/ES6
Give Given some existing 'in scope'variables, if we wanted to 'collect' them into anobject, before ES2015, we had to do:
constfname="Mark";constlname="Galloway";constaliases=["Mean Mark","The Undertaker","American Bad Ass"];conststatus="retired";constwrestler={fname:fname,lname:lname,aliases:aliases,status:status}'Collecting' An Object ES6+
Object Shorthand
constfname="Mark";constlname="Galloway";constaliases=["Mean Mark","The Undertaker","American Bad Ass"];conststatus="retired";/** * If there is no ':', * the OBJECT LITERAL automatically 'creates' a STRING 🔑 * and assigns the VALUE BOUND TO the VARIABLE IN SCOPE * that has the same name. 🦄 */constwrestler={fname,lname,aliases,status}Summarily, this is a nice way to save some typing. Less typing ➡️ fewer mistakes and 🐛s.
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse



