'Collecting' an Object Pre-ES2015/ES6
Give Given some existing 'in scope' variables, if we wanted to 'collect' them into an object, before ES2015, we had to do:
const fname= "Mark"; const lname = "Galloway"; const aliases = ["Mean Mark", "The Undertaker", "American Bad Ass"]; const status = "retired"; const wrestler = { fname: fname, lname: lname, aliases: aliases, status: status }
'Collecting' An Object ES6+
Object Shorthand
const fname= "Mark"; const lname = "Galloway"; const aliases = ["Mean Mark", "The Undertaker", "American Bad Ass"]; const status = "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. π¦ */ const wrestler = { fname, lname, aliases, status }
Summarily, this is a nice way to save some typing. Less typing β‘οΈ fewer mistakes and πs.
Top comments (0)