Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
What are immediate functions in JavaScript?
The immediate function executes as soon as it is defined. To understand the role of immediate function, let’s see the difference between a function and an immediate function −
Here’s immediate function −
(function() {
var str = "display";
}());
function display() {
// this returns undefined
alert(str);
}
Here’s a function −
var str = "display";
function display() {
// This returns "display"
alert(str);
}
Let’s see another example of immediate functions −
var name = 'Amit';
(function(sName) {
alert( 'Student name = ' + sName );
}(sName)) Advertisements
