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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With