JavaScript can be used in hardware through platforms like Esperino, which allow developers to write JavaScript code to control and interact with hardware devices over a network.