-1

In javascript, if i put

console.log("hello world")

It'll log "hello world" to console just 1 time, at the load of the page. Can i make this code run not just 1 time, but until the web page closed?

Clarity
  • 186
  • 1
  • 7
  • Give some clarifying to your question. What do you mean 'until the web page closed'? If you meant 'repeat every second' then you could put you log inside `SetInterval` function and your final code would looks like this `SetInterval(()=> console.log('Hello World!'),1000);` – Jaood_xD May 29 '22 at 17:15
  • @Jaood_xD Yeah sorry. SetInterval is "almost" solving my problem with 1000ms as i need like 1 second of execuations. It solves but "timing a code" is not the thing i'm looking. I think my question should be like this; "what can we do in situations like we cannot listen any events on the page, but still need to execute a bunch of code in a specific moment". Is the setInterval the only solution for something like this? Another example; when we're unable to listen events but need to run a code automatically, immedietaly after an if else condition turnes true on the webpage – Clarity May 29 '22 at 17:53

1 Answers1

-1
while (1) console.log("Hello, World!");
  • 2
    This is not recommended at all, it will cause the webpage (and sometimes browser) to freeze due to high cpu/memory usage. – Callum OKane May 29 '22 at 17:15
  • @CallumOKane yes, it's not the best practice for a situation like this but it corresponds 100% true to my question as an answer so I think my question wasn't descriptive enough – Clarity May 29 '22 at 18:07
  • @InfernoCheese so i will accept your comment as an answer to this topic and start a more descriptive topic to my problem – Clarity May 29 '22 at 18:18