How does the electron understand that it being observed in the double slit experiment? I was reading about the double slit experiment that proved the wave and particle nature of electron. I read that electrons give a diffraction pattern when they are not observed (wave nature) and passes through the slits separately like particles when they are observed.
My doubt is, how does the electron understand that it is being observed? What is forcing it to behave as a particle when we make an observation?
 A: "how does the electron understand that it is being observed?“
Your statement is based on the assumption that "being observed“ is a completely passive process. But that is not the case.
Let’s rephrase your question: how does the electron understand that it is being detected. Well, that’s a simple one: because it interacts with the detector! This interaction causes the electron to behave differently compared to the situation when it is not detected.
In contrast to our everyday terminology, observation always requires some form of interaction. “Seeing” the electron yourself seems not to require any other detector than yourself. But again this is not the case: it requires shining a light (shooting photons) on the electron that is bounced of (interact with) the electron to reach your eye. In reality you are not the detector; you are only part of a detector. The other part is the light source and the photons interacting with the electrons.
A: The electron doesn't 'know' anything- it simply interacts with energy and matter in accordance with the laws of physics. What physicists do is to design their experiments to investigate the nature of those interactions. When an electron is 'observed' in a two-slits experiment, what we mean is that it interacts with the particles that form the detecting screen and we see the results of the interaction. To take an old fashioned example, the detecting screen might just be a photographic film. The electron interacts with the molecules on the coating of the film causing an effect that can be seen when the film is developed. There is nothing magical about an 'observation' or 'measurement' of a particle- those words simply mean that the particle has interacted with other particles in some apparatus to cause a physical effect, and it is the effect we interpret as a measurement.
A: Electrons are quantum mechanical entities, and interact quantum mechanically with the environment. This means that there are differential wave equations, whose solutions control the probability of how an electron will interact . Probability means that an accumulation of the same boundary condition events should be made, in order tos see an effect.
In the double slit case  , the boundary conditions are "electron falling on double slit given distances separation and width of slits". This is controls the boundary conditions that choose the particular  wave-function solution. It becomes a different experiment if the electron is disturbed in order to detect which slit it went through, different boundary conditions and thus different wavefunctions .
In different words, in order to detect an electron, an interaction has to happen, all interactions disturb the original boundary conditions, and a different wavfunction will control the track of the electron destroying the coherence needed in order to sum many electrons with the same boundary conditions.
A: One way to "observe" a tiny particle like an electron is by detecting its presence via its electric field.  That detection necessarily requires that the electron disturbs some part of the the detection device's electric field if it is to be registered by that detection device.  Due to Newton's third law, the electron must be similarly disturbed.  Or if you prefer to "see" that electron with a photon, you must necessarily use a photon with a very short wavelength (aka very high energy) because the electron is so small.  That high energy photon will also disturb the electron when it reflects off of it, due to conservation of momentum.  In other words, the electron does not "understand" that it is being observed ... it is so very tiny that any force that interacts with it such that you can determine its position, will change its behavior, unlike common macroscopic objects which are so very massive that bouncing photons off of them has no discernible effect.
A: The wave equations satisfy a boundary equation with the double slit. This results in the incident wave showing an interference pattern. Whatever you do that would measure "where do these low-intensity photons cross" is actually not a double slit pattern anymore, hence you get a single gaussian fringe
A: We do not know how does it know, we just experimentaly proven that it knows. The experiment is delayed-choice quantum eraser experiment.
It basicaly does double slit experiment with a trick to produce two photons out of one AFTER it gone through the slits.
One photon travels to the detector where we observe or do not observe interference.
The other photon travels to an array of detectors in which it has 50% chance to go to a detector that tells us which slit photon gone through, and 50% chance to go to a detector which erases that information and we no longer know which slit photon went.
Surpise surprise when we knew which slit photono came through there were no interferance paterns, when we didnt interferance paterns emerged.
Fun fact, the photons that told us which slit original photon came through hit sensors 8ns later than the one which generated paters. So the photon knew what we would know (or what we will not know(which slit it came through)) 8ns later. How? We do not quite know.
Here is video explaining experiment:
https://www.youtube.com/watch?v=8ORLN_KwAgs
