I think, you must have heard about divide by zero to get infinity value, so in this example we are going to divide 100 by 0 and which will result in infinity. See the code
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <p>Click the button to display divede by zero infinity.</p> <button onclick="infinity()">Click it</button> <p id="sample"></p> <script> function infinity() { var y = 100; document.getElementById("sample").innerHTML = y/0; } </script> </body> </html>