Home > Article > Web Front-end > The Node.js environment provides these global functions!
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!