JavaScript can be used to create a gradient effect from green to red using CSS gradients. This can be achieved by defining a gradient in the CSS style of an HTML element, such as an `` or ``, and using JavaScript to dynamically change the gradient color based on user interaction or other triggers.