Tutorials Modern JavaScript (ES6+) for Beginners

Default Parameters & Object Shorthand

Learn Default Parameters & Object Shorthand in our free Modern JavaScript (ES6+) for Beginners series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

On this page
Default Parameters & Object Shorthand
Lesson 7 of 12 · Part 3 — Data & Collections · Modern JavaScript (ES6+) for Beginners
Course: Modern JavaScript (ES6+) for Beginners · Lesson: 7/12 · Read time: ~14 min · Level: Beginner · ES version: ES2015 (ES6) and above

Default Parameters & Object Shorthand

ES6 lets you give function parameters default values and write shorter object literals. Less boilerplate, fewer if (x === undefined) checks.

Default parameters

function createUser(name, role = 'student', active = true) {
  return { name, role, active };
}

createUser('Alex');                    // role student, active true
createUser('Admin', 'admin');          // active still true
createUser('Guest', 'guest', false);

Object property shorthand

const name = 'Node.js Chat Course';
const price = 499;
const currency = 'INR';

// Old
const product1 = { name: name, price: price, currency: currency };

// ES6 shorthand
const product2 = { name, price, currency };

Method shorthand in objects

const api = {
  baseUrl: 'https://api.toolliyo.com',
  getHealth() {
    return fetch(this.baseUrl + '/health');
  }
};
🌍 Real-world example — Send email with optional CC
function buildEmail({ to, subject, body, cc = [] }) {
  return { to, subject, body, cc, sentAt: new Date().toISOString() };
}

buildEmail({
  to: 'student@example.com',
  subject: 'Welcome to Toolliyo',
  body: 'Start with ES6 lesson 1.'
});
⚠️ Common Mistake: Default only triggers for undefined, not null: fn(null) does not use default — pass undefined or omit the argument.
👨‍🏫 Teaching note: Quiz: what does greet(name = "Guest") return when called with greet("")? Empty string — default not used.

Continue learning

Previous: Spread & Rest Operators (...)

Next: Array Methods — map, filter, find & reduce

Course home: All 12 lessons

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Junior Detailed
Explain JavaScript in the context of Modern JavaScript (ES6+) for Beginners.
Short answer: JavaScript runs single-threaded with an event loop. Closures capture lexical scope; promises/async handle I/O without blocking the UI thread. How to structure your answer (60–90 seconds) Define JavaScript i…
Mid Detailed
What are common mistakes teams make with Components when using Modern JavaScript (ES6+) for Beginners?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Components in plain language…
Senior Detailed
How would you debug a production issue related to State in a Modern JavaScript (ES6+) for Beginners application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define State in plain language for…
Mid Detailed
Compare two approaches to API integration—when would you choose each?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define API integration in plain lan…
Junior Detailed
Describe a real-world scenario where Performance mattered in a Modern JavaScript (ES6+) for Beginners project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. How to structure your answer (60–90 seconds) Define Performance in plain languag…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Modern JavaScript (ES6+) for Beginners
Course syllabus
Part 1 — Modern Basics
Part 2 — Write Less Code
Part 3 — Data & Collections
Part 4 — Async & Modules
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details