A junction box is needed to provide an impact-resistant safe location to connect wires within a wall. It protects spliced wires from damage and contains any sparks that might start a fire. Junction boxes are required by electrical code.
A junction box joins the main breaker to the rest of the wires in a room. Without the junction box, it would be necessary to run each wire for each fixture back to the main breaker. The junction box is usually covered by drywall and is made of either metal or plastic. Larger junction boxes are 3.5 inches deep and can hold up to five different wires. Smaller 2.5-inch boxes hold three wires.