VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascriptes6-object-literal-enhancement/

⇱ JavaScript(ES6) Object Literal Enhancement - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript(ES6) Object Literal Enhancement

Last Updated : 3 Jan, 2023
Object literal enhancement is used to group variables from the global scope and form them into javascript objects. It is the process of restructuring or putting back together. Example 1: Output : The name, color and age are now keys of dog object.
{
 name:"Duke",
 color:"Brown",
 age:5
}
Example 2: We can also create object methods with object literal enhancement. Output:
Woof Woof!!
Example 3: We can also use "this" keyword to access the object keys. Output :
Woof Woof!!, I am lilly and I am a 3 years old,
white coloured dog.Woof Woof!!
Example 4: When defining object methods, it is no longer necessary to use the function keyword. Object literal enhancement allows us to pull global variables into objects and reduces typing by making the
Comment
Article Tags: