freeCodeCamp: Challenge (Use the .env File) delete the property instead of setting it to undefined
Technically, if we are testing for a non-existing property we can’t set process.env.MESSAGE_STYLE to undefined as that is implicitly converted to a string.
Assigning a property on process.env will implicitly convert the value to a string.
This means you can’t use this logic
// process.env.MESSAGE_STYLE = 'uppercase'
let message = process.env.MESSAGE_STYLE ? {"message": "HELLO JSON"} : {"message": "Hello json"}
console.log(message) // { message: 'HELLO JSON' }
process.env.MESSAGE_STYLE = undefined;
console.log(typeof process.env.MESSAGE_STYLE) // string
message = process.env.MESSAGE_STYLE ? {"message": "HELLO JSON"} : {"message": "Hello json"}
console.log(message) // { message: 'HELLO JSON' }
But if you delete it, it works.
delete process.env.MESSAGE_STYLE
message = process.env.MESSAGE_STYLE ? {"message": "HELLO JSON"} : {"message": "Hello json"}
console.log(message) // { message: 'Hello json' }
The forum thread that made me open this issue:
https://forum.freecodecamp.org/t/use-the-end-file/498485
Test: https://github.com/freeCodeCamp/fcc-express-bground-pkg/blob/master/index.js
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 32 (32 by maintainers)
Hmm, I think this warrants some further discussion.
I do agree that
process.env.MESSAGE_STYLE = undefined;is an issue and should be fixed. However, I’m not sure thatlet message = process.env.MESSAGE_STYLE ? {"message": "HELLO JSON"} : {"message": "Hello json"}should be considered valid logic.It seems like an anti-pattern to allow a truthiness check to pass a challenge that expects a specific value.