The set trap is invoked when we set the value of a property using the assignment operator, or the Reflect.set() method. It takes four parameter-- that is, the target object, the property name, the new property value, and the receiver.
The set trap must return true if the assignment was successful. Otherwise, it will return false.
Here is a code example that demonstrates how to use the set trap:
const proxy = new Proxy({}, { set(target, property, value, receiver) { target[property] = value; return true; } }); proxy.name = "Eden";console.log(proxy.name); //Output "Eden"