0
0
Javascriptprogramming~5 mins

Object creation in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an object in JavaScript?
An object is a collection of related data and functions (called properties and methods) grouped together. It represents real-world things with characteristics and actions.
Click to reveal answer
beginner
How do you create an object using object literal syntax?
Use curly braces {} with key-value pairs inside. Example:
{ name: "Alice", age: 25 }
Click to reveal answer
intermediate
What does the new Object() syntax do?
It creates a new empty object. It's similar to using <code>{}</code> but less common. Example: <pre>const obj = new Object();</pre>
Click to reveal answer
beginner
How can you add a property to an existing object?
You can add a property by assigning a value to a new key. Example:
obj.color = "blue";
Click to reveal answer
intermediate
What is the difference between object literal and constructor function for creating objects?
Object literal creates one object directly. Constructor functions let you create many similar objects using <code>new</code>. Constructor functions act like blueprints.
Click to reveal answer
Which syntax creates an empty object in JavaScript?
A{}
B[]
Cnew Array()
Dnull
How do you access the property 'name' of an object 'person'?
Aperson[name]
Bperson:name
Cperson->name
Dperson.name
What does this code do?
const obj = new Object(); obj.age = 30;
ACreates an array with 30 elements
BCreates an object and adds an 'age' property with value 30
CThrows an error
DCreates a string '30'
Which is NOT a way to create an object in JavaScript?
AUsing object literal {}
BUsing new Object()
CUsing new Array()
DUsing a constructor function
What keyword is used with constructor functions to create new objects?
Anew
Bcreate
Cobject
Dmake
Explain how to create an object using object literal syntax and add a new property to it.
Think about how you write an object directly and then add something new.
You got /4 concepts.
    Describe the difference between creating objects with object literals and constructor functions.
    Consider when you want one object vs many similar objects.
    You got /4 concepts.