Simple(?) Question to Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:
Hi,
i’m working on the exercise tracker and i got a question.

There are two routes which are pretty similar and i can’t figure out what the difference between this two is. (I didn’t complete the exercise yet.)

The two routes are the following:

First: GET /api/users/:_id/logs

Second: GET /api/users/:id/logs

I see that there is an underscore bevore the id in the first route but for my understanding i can’t figure out, why it ist there and what it does.

May somebody can answer my question.

Greetings,
mrnilas

On the back-end using the route GET /api/users/:_id/logs would allow you to access a user id with req.params._id. The other route would allow you to access a user id with req.params.id. The underscore is just another character in the route parameter. Nothing special about it at all.

The same would go for a variable in code with or with an underscore:

for (let i = 0; i < 5; i++) {
  console.log(i);
}

The above yields:

0
1
2
3
4

Changing the i to _id yields the same results:

for (let _i = 0; i < 5; _i++) {
  console.log(_i);
}

I’m not really sure why it is shown like that in the tests list. I think they should all use the same parameter name. I can see how it might be confusing otherwise.

As said, they are not different routes, it’s just the parameter name that is shown differently for some of the tests. You can name the parameter whatever you like (as long as you use it correctly).

Thanks for your explanation RandellDawson!

Like lasjorg said it’s a bit counfusing that there are the “two” parameter shown in the test list.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.