Bird
0
0

Given this Node.js Lambda code snippet:

medium📝 Predict Output Q4 of 15
AWS - Lambda
Given this Node.js Lambda code snippet:
exports.handler = async () => {
  return process.env.MY_VAR || 'default';
};

If the environment variable MY_VAR is set to hello, what will the function return?
A'hello'
B'default'
Cundefined
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment variable usage in Node.js

    process.env.MY_VAR accesses the environment variable MY_VAR; if set, it returns its value.
  2. Step 2: Evaluate the code with MY_VAR='hello'

    Since MY_VAR is set to 'hello', the expression returns 'hello' instead of the default.
  3. Final Answer:

    'hello' -> Option A
  4. Quick Check:

    Env var set returns its value, not default [OK]
Quick Trick: Env var returns value if set, else default [OK]
Common Mistakes:
  • Assuming default is returned even if variable is set
  • Confusing undefined with null
  • Not using process.env in Node.js

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes