Bird
0
0

Given this Remix loader code snippet, what will be the value of apiUrl if process.env.API_URL is undefined?

medium📝 component behavior Q13 of 15
Remix - Deployment
Given this Remix loader code snippet, what will be the value of apiUrl if process.env.API_URL is undefined?
export async function loader() {
  const apiUrl = process.env.API_URL || 'https://default.api.com';
  return { apiUrl };
}
AThrows an error
Bundefined
C'https://default.api.com'
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Understand the || operator behavior

    If process.env.API_URL is undefined (falsy), the expression returns the right side string.
  2. Step 2: Apply to given code

    Since process.env.API_URL is undefined, apiUrl becomes 'https://default.api.com'.
  3. Final Answer:

    'https://default.api.com' -> Option C
  4. Quick Check:

    Falsy env var uses default string [OK]
Quick Trick: Use || to provide default if env var is missing [OK]
Common Mistakes:
MISTAKES
  • Expecting undefined instead of default string
  • Thinking it throws an error if env var missing
  • Confusing null with undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes