We often use anonymous functions as arguments of other functions. For example:
setTimeout(function () {
console.log('Execute later after 1 second')
}, 1000);Code language: JavaScript (javascript)
We often use anonymous functions as arguments of other functions. For example:
setTimeout(function () {
console.log('Execute later after 1 second')
}, 1000);Code language: JavaScript (javascript)
anonymous functions javascript
// Regular function, called explicitly by name .aka “named function”
function multiply(a, b){
var result = a * b;
console.log(result);
}
multiply(5, 3);
// Anonymous function stored in variable.
// Invoked by calling the variable as a function
// Anonymous functions don't have a name,
// so the parentheses appears right after “function” keyword.
var divided = function() {
var result = 15 / 3;
console.log("15 divided by 4 is " + result);
}
divided();
// Immediately Invoked Function Expression.
// Immediately invoked function expressions are anonymous functions
// with another parentheses pair at the end to trigger them,
// all wrapped inside parentheses.
// Runs as soon as the browser finds it:
(function() {
var result = 20 / 10;
console.log("20 divided by 10 is " + result);
}())
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us