JavaScript Objects Interview Questions

    Question 1: Creating Objects

    Which of the following correctly creates an object in JavaScript?

    Question 2: Accessing Properties

    How do you access the value of property name in the object person?

    Question 3: Adding Properties

    Which code correctly adds a property age with value 25 to an object user?

    Question 4: Object.keys()

    What does Object.keys(obj) return?

    Question 5: Object.values()

    What will the following code output?

    let car = { brand: "Tesla", model: "X" }; console.log(Object.values(car));

    Question 6: Checking Property Existence

    Which operator checks if an object has a given property?

    Question 7: Object.freeze()

    What does Object.freeze(obj) do?

    Question 8: Object Destructuring

    What will this code output?

    let user = { name: "Alice", age: 22 }; let { name } = user; console.log(name);

    Question 9: JS For...in Loop

    What is the output?

    let obj = {a:1, b:2}; for (let key in obj) { console.log(key); }

    Question 10: Object.assign()

    What does Object.assign(target, source) do?