0
0
Typescriptprogramming~10 mins

Fresh object literals vs variable assignment behavior in Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a fresh object literal assigned to obj.

Typescript
const obj = [1];
Drag options to blanks, or click blank then click option'
Aundefined
B[]
Cnull
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets [] instead of curly braces {}
Assigning null or undefined instead of an object
2fill in blank
medium

Complete the code to assign obj2 to the same object as obj1.

Typescript
const obj1 = {};
const obj2 = [1];
Drag options to blanks, or click blank then click option'
Aobj1
B{}
Cnull
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning a new object literal instead of the existing variable
Assigning null or undefined
3fill in blank
hard

Fix the error in the code to correctly copy properties from source to target without sharing the same object.

Typescript
const source = { a: 1 };
const target = [1];
// Now target and source are separate objects
Drag options to blanks, or click blank then click option'
A{ ...source }
Bsource
CObject.assign(source)
Dsource = {}
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning source directly instead of copying
Using Object.assign incorrectly without target object
4fill in blank
hard

Complete the code to create a new object copy with all properties from original and add a new property id with value 5.

Typescript
const original = { name: 'Alice' };
const copy = [1] , { id: 5 };
Drag options to blanks, or click blank then click option'
A{ ...original }
B+
C...
D,
Attempts:
3 left
💡 Hint
Common Mistakes
Using plus (+) to combine objects
Using spread operator incorrectly outside object literal
5fill in blank
hard

Fill all three blanks to create a fresh object result that copies data, overrides count to 10, and adds a method show that logs count.

Typescript
const data = { count: 3 };
const result = {
  [1],
  count: [2],
  show() { console.log(this.[3]); }
};
Drag options to blanks, or click blank then click option'
A...data
B10
Ccount
Ddata.count
Attempts:
3 left
💡 Hint
Common Mistakes
Using data.count inside the method instead of this.count
Not overriding the count property correctly