Bird
0
0

Given this Angular interceptor code snippet, what will be the Authorization header value in the outgoing HTTP request if the token is 'abc123'?

medium📝 component behavior Q13 of 15
Angular - HTTP Client
Given this Angular interceptor code snippet, what will be the Authorization header value in the outgoing HTTP request if the token is 'abc123'?
intercept(request: HttpRequest, next: HttpHandler) {
  const token = 'abc123';
  const cloned = request.clone({
    headers: request.headers.set('Authorization', `Bearer ${token}`)
  });
  return next.handle(cloned);
}
AAuthorization: Bearer abc123
BAuthorization: abc123
CAuthorization: Bearer token
DNo Authorization header will be added
Step-by-Step Solution
Solution:
  1. Step 1: Check how the token is added

    The code sets the Authorization header to 'Bearer ' plus the token string 'abc123'.
  2. Step 2: Understand string interpolation

    The template string `Bearer ${token}` becomes 'Bearer abc123'.
  3. Final Answer:

    Authorization: Bearer abc123 -> Option A
  4. Quick Check:

    Header value = 'Bearer abc123' [OK]
Quick Trick: Template strings insert token value directly [OK]
Common Mistakes:
MISTAKES
  • Forgetting 'Bearer ' prefix
  • Using the literal word 'token' instead of variable
  • Assuming header is not added

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes