Shorthand Property Name and Shorthand Method Name

Last Updated On Friday 27th Aug 2021

ES6 Shorthand Property Name

  • You can simplify the following code with ES6 shorthand property.
	let id = 1,
    name = 'Jake Halliday'
let obj = {
    id: id,
    name: name
}

console.log(obj) // { id: 1, name: 'Jake Halliday' }
	
	let id = 1,
    name = 'Jake Halliday'
let obj = {
    id,
    name
}

console.log(obj) // { id: 1, name: 'Jake Halliday' }
	

ES6 Shorthand Method Name

  • You can simplify the following code with ES6 shorthand method name.
	let obj = {
  say: function(msg) {
    console.log(msg)
  }
}

obj.say("Hey Folks!!") // Hey Folks!!
	
	let obj = {
  say(msg) {
    console.log(msg)
  }
}

obj.say("Hey Folks!!") // Hey Folks!!
	

References