EN
JavaScript - why can I add custom field to function
1 answers
3 points
Can someone explain to me why can I add custom field to a function and doesn't get any errors?
For example:
xxxxxxxxxx
1
function myFunction() {
2
console.log('hello from myFunction');
3
}
4
5
myFunction.field = 'example value';
6
7
console.log(myFunction.field); // Output: 'example value'
1 answer
3 points
In JavaScript functions are first-class objects and they can have properties and methods just like any other object. That's why you don't get any errors when you assign a new field to it.
References
0 commentsShow commentsAdd comment