why did compass needle gets diflected when kept close to electromagnet ?
A magnetic compass aligns along the direction of earth’s magnetic field and also along the direction of the magnetic field of a bar magnet. Which clearly indicates that a compass needle interacts with the magnetic field of a magnetic material. When current flows through an electromagnet it behaves like a magnetic material. So, the compass needle shows deflection when brought near an electromagnet.