0

I really want to find a way to add a simple pause in JS, I know this is a duplicate question, but I cannot find a good answer! Please see my example in code below.

Console.log ('hello world!')
//here is where I want to insert a pause!
Console.log ('how are you?')

This way, the two lines of text will have about a three second pause (or however long) in-between.

Coder
  • 1
  • 1
  • setTimeout or async/await – user120242 May 16 '20 at 02:25
  • Is it a timed pause or an indefinite pause? Please clarify? – shuberman May 16 '20 at 02:28
  • Could you show me some quick code, just to show me how you would use them in Console.log ? – Coder May 16 '20 at 02:29
  • 2
    Do you literally want to freeze execution of JS and all that depends on it? I mean you say ***legitimate***, which seems to suggest that the solutions you found are not legit. Why are they not legit? –  May 16 '20 at 02:30
  • `console.log('hello world!'); setTimeout(()=>console.log('how are you?'),3000);` ya.. you seem to be implying that this does not seem legitimate to you. that's kind of an opinion on how you think the language should be designed to suit a convenience, but unfortunately such a convenience would contradict the way execution flow would work. – user120242 May 16 '20 at 02:30
  • Ok, I have to admit, I am a beginner, and I haven't found other answers to be completely useful.....I am sure they are legit, but I'm not a complete pro..... – Coder May 16 '20 at 02:32
  • There's a reason why a simple "pause" doesn't exist, at least in browsers. Blocking the main execution thread also freezes the web page. Is this being executed in a browser? –  May 16 '20 at 02:34
  • No, slappy, just in a JS running system app... Not for a website. – Coder May 16 '20 at 02:36
  • If it's a node app you can use Atomics.wait, (or I guess workers now too) – user120242 May 16 '20 at 02:44
  • User120242, I entered the code you gave me, it worked..... Thank you! Just like I wanted! – Coder May 16 '20 at 12:03

0 Answers0