Q:

What is the difference between "If" and "When" in a conditional clause?

For these two expressions:

I will give it to you when I no longer need it.
I will give it to you if I no longer need it.

Let us say it is an object such as a book or a laptop or something similar.
Is there any difference between the meanings of these two sentences?

A:

The first assumes that a time will definitely come when the speaker’s need for the object comes to an end. The second makes no such assumption.

