Yes you can use a junction box to extend wiring. You should use a junction box if your existing wiring does not reach its intended end point. Use the correct wires for both the source and the extension. Ensure that both the gauge and the insulation meet the electrical code requirements. To extend the wires far enough to reach the new location, a junction box may be required. If the distance is shorter, the wires can be shortened and there will be no need for a junction.