jskatas.org Continuously Learn JavaScript. Your Way.

Object literal: basics

ES6 has new shorthands for objects.

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

The object literal allows for new shorthands

with variables

  • the short version for {x: x} is {x}
  • works with multiple variables too

with methods

  • using the name only uses it as key
  • a different key must be given explicitly, just like before ES6
  • inline functions, can written as obj={func(){}} instead of obj={func:function(){}}