To set a background image in JavaScript, you can manipulate the CSS styles of an element. Use the `style` property to assign a URL to the `backgroundImage` property. For example, `document.body.style.backgroundImage = 'url("image.jpg")';` adjusts the background of the body element instantly, creating a visually appealing effect.