Most modern sewing machines have this function built in, but many older machines do not, and straight stitch machines can not sew a zigzag stitch with which buttonholes are constructed.
It is a back-and-forth stitch used where a straight stitch will not suffice, such as in reinforcing buttonholes, in stitching stretchable fabrics, and in temporarily joining two work pieces edge-to-edge.