If and whether are sometimes interchangeable but they 
have different uses.

You can use both if and whether in indirect questions:

She asked if I wanted tea or coffee.
She asked whether I wanted tea or coffee.

Whether is used in more formal contexts.

This is the main difference between if and whether:

IF

Use if where a condition is involved:

If it doesn’t rain tomorrow, we’ll play golf.
I’d be grateful if you could pick me up at the railway station.

WHETHER

Use whether in reference to alternatives or a choice:

We discussed whether we should walk or take a taxi.

Use whether before an infinitive:

I’ve been wondering whether to let him use the car again.

Use whether after a preposition:

They talked about whether it was a mistake.

A lone woman is sitting on a grassy beach by a large lake.
She debated with herself whether to take a swim or go for a walk

To understand the difference between if and whether, look at these two examples:

1. Let me know if you got his letter.

If you got his letter, tell me so, but only if you got it. You don’t have to tell me if you did not get his letter.

2. Let me know whether you got his letter.

No matter whether you got his letter or not, please tell me.