Telling null From undefined

On the new server, nobody set BACKUP_BUCKET, and the sysadmin’s Python check refused to start because bucket is None was true. The JavaScript port has to catch it too. That takes care, because JavaScript has two values for “nothing here.”

Watch an Unset Bucket Slip Past

The port reads its settings from process.env, the counterpart of os.environ provided by Node, not by JavaScript itself. Set variables are strings, and dot access behaves like os.environ.get(), never raising a KeyError.

In the natural port, Python’s bucket is None and region is None become === null, since null is what JavaScript code uses for None:

```js file=backup-check.js const bucket = process.env.BACKUP_BUCKET; let region = process.env.BACKUP_REGION; const mode = “live”; const retries = 3;

if (region === null) { region = “eu-west-1”; }

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.