Object Constructors — JS Technical Interview Questions & Answers

Creating objects with the new keyword and constructor functions.

Object Constructors

  • Object Constructors (js) is a JS topic. In plain words you use it for let total = 0 in a cart script. Don’t start with a slogan — start with that picture.
  • Smallest example: let for change, const for fixed. Type it, run it, and say what you see. If you can do that from memory, you know Object Constructors (js).
  • From the example next to this theory: Creating objects with the new keyword and constructor functions.
  • Trap: var leak / const reassign. Fix that before you talk about advanced JS.
  • Viva: what is Object Constructors (js)? Then show let for change, const for fixed. Then name the trap.

Technical Interview Tip: What is Object Constructors (js)? Show this: let for change, const for fixed. Trap: var leak / const reassign.

Code Examples for Object Constructors

Object Constructors — working example

const user = {
  name: "Ada",
  city: "Pune",
  skills: ["JS"],
  get label() {
    return this.name + " @" + this.city;
  },
};
user.skills.push("SQL");
user["role"] = "dev";
console.log(user.label, user.skills);

function Person(name) {
  this.name = name;
}
const p = new Person("Lin");
console.log(p.name);

const config = Object.freeze({ theme: "light" });
// config.theme = "dark"; // TypeError in strict mode
console.log(config.theme);

Object Constructors — objects store keyed values; constructors make instances; getters compute; freeze/seal lock mutation.

How to Explain Object Constructors to an Interviewer

What is Object Constructors (js)?

Used for let total = 0 a cart script Not just the heading

Give one small example of Object Constructors (js).

let for change, const for fixed Creating objects with the new keyword and constructor functions

What mistake do beginners make with Object Constructors (js)?

var leak / const reassign Show the fix

Where do you use Object Constructors (js)?

a cart script let total = 0