Câu hỏi phỏng vấn Nodejs
Câu hỏi

What are the Timing ...

Câu trả lời

Node.js offers a variety of timing features that allow developers to schedule and control the execution of code based on time intervals or at specific points in time. These features are part of the global Timers module, which means they are available without the need to import them using the require keyword. Here are the main timing features in Node.js:

setTimeout() and clearTimeout()

The setTimeout() function is used to execute a callback function after a specified delay, measured in milliseconds. It is useful for scheduling a function to run once after a delay. If you need to cancel a timeout, you can use the clearTimeout() method, which cancels a Timeout object created by setTimeout()[1][2][3][5][6][8].

setInterval() and clearInterval()

The setInterval() function repeatedly executes a callback function at a specified interval, also in milliseconds. This is ideal for running a function at regular intervals. If you want to stop the repeated execution, you can use the clearInterval() method to cancel an Interval object created by setInterval()[1][2][3][5][6][8].

setImmediate() and clearImmediate()

The setImmediate() function is used to execute a callback function immediately after the current poll phase of the event loop completes, effectively deferring the execution until the stack is clear. To cancel an Immediate object created by setImmediate(), you can use the clearImmediate() method[1][2][3][5].

process.nextTick()

The process.nextTick() function schedules a callback function to be invoked in the next iterati...

senior

senior

Gợi ý câu hỏi phỏng vấn

middle

Could we run an external process with Node.js?

junior

What do you mean by Asynchronous API?

middle

What is stream and what are types of streams available in Node.js?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào