Reputation: 147
I have code:
function fn(ob)
{
console.log(ob.name)
}
fn({name:"myName"})
(function(text){
console.log(text)
})("Error")
But when i run this i get TypeError: fn(...) is not a function [Learn More] on console. Why?
Upvotes: 3
Views: 34
Reputation: 62566
You need to separate between the call to the fn
function and the definition (and call) to the anonymous function.
You can do this using the ;
char after the call to the fn
function:
function fn(t) {
console.log(t.name)
}
fn({name:"myName"});
(function(text){
console.log(text)
})("Error")
Otherwise your code is actually:
fn({name:"myName"})(function(text){
console.log(text)
})("Error")
And this is the error you got.
Upvotes: 3