Objects Practice Sheet
Question 1: Create a simple object
Question: Ek simple object create karo jo ek person ka name aur age store karta ho.
Explanation: Humne ek object person
create kiya jisme name
aur age
properties hain.
Question 2: Access object properties
Question: Ek object ki properties ko access karo aur print karo.
Explanation: Dot notation use karke hum object ki properties ko access karte hain.
Question 3: Update object properties
Question: Ek object ki properties ko update karo.
Explanation: Humne name
property ko update kiya aur new value “Jane” set ki.
Question 4: Add new property to an object
Question: Ek naye property ko ek existing object mein add karo.
Explanation: Humne city
property ko add kiya aur uski value “New York” set ki.
Question 5: Delete a property from an object
Question: Ek property ko delete karo ek object se.
Explanation: delete
operator use karke humne age
property ko delete kar diya.
Question 6: Check if a property exists in an object
Question: Check karo ki ek specific property object mein exist karti hai ya nahi.
Explanation: in
operator use karke check kiya ki name
property object mein exist karti hai ya nahi.
Question 7: Loop through object properties
Question: Object ki sabhi properties ko loop karke print karo.
Explanation: for...in
loop use karke humne sabhi properties aur unki values ko print kiya.
Question 8: Nested objects
Question: Ek nested object create karo aur uski nested properties ko access karo.
Explanation: Humne ek nested object address
create kiya aur uski city
property ko access kiya.
Question 9: Merge two objects
Question: Do objects ko merge karo.
Explanation: Object.assign
method use karke do objects ko merge kiya.
Question 10: Copy an object
Question: Ek object ko copy karo.
Explanation: Object.assign
method use karke humne original
object ki copy banayi.
Question 11: Object destructuring
Question: Object destructuring use karke properties ko variables mein assign karo.
Explanation: Object destructuring se person
object ki properties ko alag-alag variables mein assign kiya.
Question 12: Computed property names
Question: Computed property names ka use karke ek object create karo.
Explanation: Computed property names se prop
variable ki value ko property name banaya.
Question 13: Function inside object
Question: Ek function ko ek object ke andar define karo aur usse call karo.
Explanation: car
object mein ek method getBrand
define kiya aur use call kiya.
Question 14: this
keyword in object method
Question: this
keyword ka use karke ek object method mein property access karo.
Explanation: this
keyword se current object ki name
property access ki.
Question 15: Arrow function as object method
Question: Arrow function ko ek object method ke tarah define karo aur call karo.
Explanation: Arrow functions this
context ko lexically bind karte hain, isliye name
undefined mila.
Question 16: Object.keys() method
Question: Object.keys
method ka use karke object ke keys ko array mein convert karo.
Explanation: Object.keys
method se object ke keys ki array banayi.
Question 17: Object.values() method
Question: Object.values
method ka use karke object ke values ko array mein convert karo.
Explanation: Object.values
method se object ke values ki array banayi.
Question 18: Object.entries() method
Question: Object.entries
method ka use karke object ke key-value pairs ko array of arrays mein convert karo.
Explanation: Object.entries
method se object ke key-value pairs ki array banayi.
Question 19: Using a constructor function to create objects
Question: Ek constructor function define karo aur uska use karke objects create karo.
Explanation: Constructor function Person
define kiya aur new
keyword se objects create kiye.
Question 20: Prototype property
Question: Ek object ki prototype property set karo aur uska use karo.
Explanation: Prototype property se greet
method ko sabhi Person
instances mein add kiya.
Question 21: Object.create() method
Question: Object.create
method ka use karke ek new object create karo.
Explanation: Object.create
se proto
ko prototype banake new object create kiya.
Question 22: Object.freeze() method
Question: Object.freeze
ka use karke ek object ko freeze karo aur uske properties ko change karne ki koshish karo.
Explanation: Object.freeze
se object ko immutable banaya, changes apply nahi hue.
Question 23: Object.seal() method
Question: Object.seal
ka use karke ek object ko seal karo aur usme naye properties add karne ki koshish karo.
Explanation: Object.seal
se object ko seal kiya, properties update hui lekin naye properties add nahi hui.
Question 24: Object.assign() method
Question: Object.assign
ka use karke ek object ki properties ko copy karo.
Explanation: Object.assign
se source
object ki properties ko target
object mein copy kiya.
Question 25: Creating methods in an object
Question: Ek object mein methods define karo aur call karo.
Explanation: calculator
object mein add
aur subtract
methods define kiye aur call kiye.
Question 26: Object property shorthand
Question: Object property shorthand ka use karke ek object create karo.
Explanation: Object property shorthand se variables name
aur age
ko direct properties banaya.
Question 27: Dynamic property names
Question: Dynamic property names ka use karke ek object create karo.
Explanation: Dynamic property names se key
variable ki value ko property name banaya.
Question 28: Object property value shorthand
Question: Object property value shorthand ka use karke ek object create karo.
Explanation: Property value shorthand se existing variables ko direct properties banaya.
Question 29: Spread operator with objects
Question: Spread operator ka use karke do objects ko merge karo.
Explanation: Spread operator ...
se obj1
aur obj2
ko merge kiya.
Question 30: Object with a method using this
Question: Ek object mein method define karo jo this
ka use karke object properties access kare.
Explanation: greet
method mein this
keyword use karke name
property access ki.
Question 31: Factory function to create objects
Question: Ek factory function define karo jo objects create kare.
Explanation: Factory function createUser
define kiya jo new user objects create karta hai.
Question 32: Chaining object methods
Question: Ek object define karo jisme methods chaining support karte ho.
Explanation: Methods add
aur subtract
ko chaining support karne ke liye return this
kiya.
Question 33: Using Object.defineProperty
Question: Object.defineProperty
ka use karke ek object property define karo with getter aur setter.
Explanation: Object.defineProperty
se fullName
property define ki jo getter aur setter use karti hai.
Question 34: Converting an object to JSON
Question: Ek object ko JSON string mein convert karo.
Explanation: JSON.stringify
method se object ko JSON string mein convert kiya.
Question 35: Parsing a JSON string to an object
Question: Ek JSON string ko object mein parse karo.
Explanation: JSON.parse
method se JSON string ko object mein convert kiya.
Question 36: Object.entries() with for…of loop
Question: Object.entries
aur for...of
loop ka use karke object ke key-value pairs ko loop karo.
Explanation: Object.entries
se key-value pairs ko array mein convert kiya aur for...of
loop use karke iterate kiya.
Question 37: Object.fromEntries() method
Question: Object.fromEntries
method ka use karke key-value pairs ki array ko object mein convert karo.
Explanation: Object.fromEntries
method se key-value pairs ki array ko object mein convert kiya.
Question 38: Using a symbol as a key
Question: Ek symbol ko ek object key ke tarah use karo.
Explanation: Symbol sym
ko object key ke tarah use kiya aur uski value access ki.
Question 39: Object literal enhancement
Question: Object literal enhancement ka use karke ek object create karo.
Explanation: Object literal enhancement se existing variables aur method ko direct object mein add kiya.
Question 40: Object destructuring with default values
Question: Object destructuring ka use karke default values assign karo.
Explanation: Object destructuring se age
property ki default value 30 assign ki jab property exist nahi karti.
Question 41: Object destructuring with rest operator
Question: Object destructuring ka use karke rest operator ko implement karo.
Explanation: Rest operator ...rest
se baki properties ko ek naya object rest
mein assign kiya.
Question 42: Checking if a key exists using hasOwnProperty
Question: hasOwnProperty
method ka use karke check karo ki ek key object mein exist karti hai ya nahi.
Explanation: hasOwnProperty
method se check kiya ki name
aur city
properties object mein exist karti hain ya nahi.
Question 43: Enumerate properties with Object.getOwnPropertyNames
Question: Object.getOwnPropertyNames
method
ka use karke object ki sabhi properties ko enumerate karo.
Explanation: Object.getOwnPropertyNames
method se object ki sabhi properties ki array banayi.
Question 44: Object.preventExtensions()
Question: Object.preventExtensions
ka use karke ek object ko non-extensible banao aur naye properties add karne ki koshish karo.
Explanation: Object.preventExtensions
se object ko non-extensible banaya, naye properties add nahi hui.
Question 45: Object.isExtensible()
Question: Object.isExtensible
ka use karke check karo ki ek object extensible hai ya nahi.
Explanation: Object.isExtensible
method se check kiya ki object extensible hai ya nahi.
Question 46: Setting a prototype with Object.setPrototypeOf
Question: Object.setPrototypeOf
ka use karke ek object ka prototype set karo.
Explanation: Object.setPrototypeOf
se rabbit
object ka prototype animal
set kiya.
Question 47: Using a getter to compute a property
Question: Ek getter define karo jo ek property ko compute kare.
Explanation: Getter area
define kiya jo length
aur width
properties se area compute karta hai.
Question 48: Using a setter to set a property
Question: Ek setter define karo jo ek property ko set kare.
Explanation: Setter fullName
define kiya jo firstName
aur lastName
properties ko set karta hai.
Question 49: Object property flags
Question: Object.defineProperty
ka use karke ek property ko non-enumerable banao.
Explanation: Object.defineProperty
se name
property ko non-enumerable banaya.
Question 50: Creating an object with null prototype
Question: Ek object create karo jiska prototype null ho.
Explanation: Object.create(null)
se ek object create kiya jiska prototype null hai.
Yeh 50 questions aapko JavaScript objects ke concepts ko samajhne aur practice karne mein madad karenge.