Problem: Auto-Default Missing Values
Problem statement
In your application, several components depend on configuration keys that may not exist yet. Currently, accessing a missing property simply returns undefined, which later causes runtime errors or confusing logs.
You want a safer approach: when a property is missing, it should return a default placeholder, such as "N/A", instead of undefined.
This will help modules safely read from incomplete configurations without crashing.
Goal
Wrap the given configuration object config in a Proxy that returns "N/A" whenever a non-existent property is accessed.
Constraints
You must use the
gettrap.Do not modify the original object.
The Proxy should still return real values for existing keys.
Only missing keys should return the default placeholder.
Sample output
The examples below illustrate what the output should look like:
console.log(safeConfig.appName);/* Expected output:'NodeMaster'*/console.log(safeConfig.debug);/* Expected output:'N/A'*/console.log(safeConfig.version);/* Expected output:'1.2.0'*/console.log(safeConfig.license);/* Expected output:'N/A'*/
Good luck trying the problem! If you’re unsure how to proceed, check the “Solution” tab above.
Problem: Auto-Default Missing Values
Problem statement
In your application, several components depend on configuration keys that may not exist yet. Currently, accessing a missing property simply returns undefined, which later causes runtime errors or confusing logs.
You want a safer approach: when a property is missing, it should return a default placeholder, such as "N/A", instead of undefined.
This will help modules safely read from incomplete configurations without crashing.
Goal
Wrap the given configuration object config in a Proxy that returns "N/A" whenever a non-existent property is accessed.
Constraints
You must use the
gettrap.Do not modify the original object.
The Proxy should still return real values for existing keys.
Only missing keys should return the default placeholder.
Sample output
The examples below illustrate what the output should look like:
console.log(safeConfig.appName);/* Expected output:'NodeMaster'*/console.log(safeConfig.debug);/* Expected output:'N/A'*/console.log(safeConfig.version);/* Expected output:'1.2.0'*/console.log(safeConfig.license);/* Expected output:'N/A'*/
Good luck trying the problem! If you’re unsure how to proceed, check the “Solution” tab above.