Axis Clamping Question

How can I clamp an objects rotation and position along certain axis with javascript, like in a 2d game where the character can't move towards the camera, just up, down left, and right?

Take a look at ConfigurableJoint. With this Component attached you can restrict movement and rotation to certain axes.