Always use the designated holes or brackets on the junction box to secure it to the wall. They can be screwed onto wall studs or ceiling joists. A junction box is a protective container designed to house and safeguard the splices, taps, or connections of electrical conductors. It keeps wires from touching hands, dust, water, and each other. The National Electrical Code (NEC), published as NFPA 70, sets minimum safety standards for electrical junction boxes in residential and commercial buildings.
[PDF Version]