Home > Web Front-end > JS Tutorial > body text

The Node.js environment provides these global functions!

藏色散人
Release: 2022-08-08 11:29:38
forward
1538 people have browsed it

This article will give you a detailed introduction to the global functions under Node.js. I hope it will be helpful to friends in need!

1. Global functions under Node.js

1.1 The global functions provided by JavaScript language are still available under Node.js

• parseInt/parseFloat/isNaN/isFinite/eval..

• One-shot timer (setTimeout / clearTimeout)

• Periodic timer (setInterval / clearInterval )

1.2 The Node.js environment also provides some global functions

• Immediate execution of timer (setImmediate/clearImmediate)

First Run the main program. When the main program finishes running, the nextTick function is the end of the main program. It is executed immediately after the main process ends. Then run the setImmediate function, the event queue head function, which is executed immediately before the event queue starts. Finally, the setTimeout function in the event queue is executed.

The main program is synchronous and the event queue is asynchronous. When the main program is executed, the event queue will be notified to execute. If the function is not loaded immediately, such as setTimeout, it will be lost in the event queue. After the main program is executed, it notifies the event queue, and then executes it sequentially from the head to the inside.

##1.3 The Node.js environment also provides other global functions

• Execute immediately Timer (setImmediate/clearImmediate)

Just talked about.

• The process immediately executes the timer (process.nextTick)

The second function provided by the Node environment.

1.4 Example

Through the example we see that the execution sequence is

1.num variable printing.

2.process.nextTick() function is executed immediately after the main program ends after the variable is printed.

3.setImmediate() function, after the tail function of the main program is executed, execute the function at the head of the event queue.

4.setTimeout() function, an internal function executed after executing the function at the head of the event queue.

【Recommended:

node.js video tutorial

The above is the detailed content of The Node.js environment provides these global functions!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template