if we hammer a electromagnet does it lose the properties?
No, they don't. In electromagnets the magnetic property is due to the alignment of the atoms in a particular direction, when you hammer the electromagnet they get disoriented but as soon as the hammering stops the electricity realigns them and thus they do not lose the property.
The same does not happen in the case of bar magnet the change is permanent and hence they lose the magnetic property.
The same does not happen in the case of bar magnet the change is permanent and hence they lose the magnetic property.