MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Enhanced Object Literals0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
HomeTutorialsJavaScript for IntermediateEnhanced Object Literals
Arrow Functions Advanced

Enhanced Object Literals

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

ECMAScript 2015 introduced several syntactic enhancements to object literal notation, making object creation concise, expressive, and less repetitive.


1. Property Value Shorthand

Before ES6, assigning a variable to an object property with the same name required duplicating the identifier:

1const name = "Full-Stack Web Development";
2const duration = "12 Months";
3const price = 49999;
4 
5// The Old Way (ES5):
6const courseOld = {
7 name: name,
8 duration: duration,
9 price: price
10};
11 
12// The Enhanced ES6 Shorthand:
13const courseNew = {
14 name,
15 duration,
16 price
17};

If the property name matches the variable name, write it once!


2. Method Definition Shorthand

You can define methods without typing the function keyword or colon : :

1// The Old Way:
2const calculatorOld = {
3 add: function(a, b) {
4 return a + b;
5 }
6};
7 
8// The Modern Shorthand:
9const calculatorNew = {
10 add(a, b) {
11 return a + b;
12 },
13 subtract(a, b) {
14 return a - b;
15 }
16};

3. Computed Property Names ([expression])

Before ES6, to create an object whose property key was dynamic or computed from an expression, you had to instantiate the object first and then use bracket notation on a separate line:

1// The Old Way:
2const prefix = "user_";
3const dynamicKey = prefix + "role";
4 
5const userOld = {};
6userOld[dynamicKey] = "admin";

With ES6 Computed Property Names:

You can calculate the property key directly inside the object literal using square brackets [...]:

1const prefix = "user_";
2const roleType = "admin";
3 
4const userNew = {
5 id: 101,
6 [`${prefix}status`]: "active",
7 [`${prefix}role`]: roleType,
8 [1 + 2]: "three"
9};
10 
11console.log(userNew.user_status); // "active"
12console.log(userNew.user_role); // "admin"
13console.log(userNew[3]); // "three"

4. Real-World Use Case: Dynamic Form Handlers

Computed properties are universally used in form handlers (like React onChange events):

1function handleInputChange(fieldName, value) {
2 // Update state immutably using computed property:
3 formData = {
4 ...formData,
5 [fieldName]: value
6 };
7}
8 
9handleInputChange("email", "sumit@mskinstitute.com");

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What does property value shorthand allow you to write instead of { title: title }?
Question 2
What is the concise ES6 method shorthand syntax for defining a method greet inside an object?
Question 3
How do you create an object property key dynamically from an expression directly within the object literal?
Question 4
If const key = "marks"; const obj = { [key]: 95 };, what is the output of obj.marks?
Question 5
Can computed property names contain complex string concatenations or function calls?
Next Lesson

Arrow Functions Advanced

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Default ParametersArrow Functions Advanced

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext