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

Detailed explanation of js immediate execution function instance

小云云
Release: 2018-03-08 15:20:30
Original
1543 people have browsed it

This article mainly shares with you js immediate execution function examples, hoping to help everyone.

for(var i=0;i<5;i++){
			(function(i){
				setTimeout(function(){
					console.log(i);
				},0);
			})(i);
		}
		//0 1 2 3 4
Copy after login

The immediate execution function will execute the code inside immediately. Even if it contains asynchronous execution code, it will be executed immediately.

for(var i=0;i<5;i++){
			setTimeout(function(){
				console.log(i);
			},0);
		}
		//5 5 5 5 5
Copy after login

Related recommendations:

Example detailed explanation of JavaScript immediately Execution function

Detailed explanation of JavaScript anonymous, named function and immediate execution function IIFE

Immediate execution function in JS

The above is the detailed content of Detailed explanation of js immediate execution function instance. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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