⏱ 0:02est. 3 min
Chapter 34- Functions are Objects
Notes
#BIGWORD First Class Function (FCF) - Everything you can do with other types you can do with functions . Assign them to variables, pass them around, create them on the fly.
- Functions reside in memory
- It's a special type of object because it has all the features of the normal object as well as some special properties
- We can attach primitive, object, functions to a function
Two special properties of functions are
- Name - optional,can be anonymous
- Code - The actual lines of code you have written is set in this property. The code you write is one of the property you are adding one to it. This property is invocable
Example 1
function greet(){
console.log("hi");
}
//As we know functions are the objects, we can add a property to it
greet.language = "english";
console.log(greet);
Output - we get only text of the function we wrote
function greet(){
console.log("hi");
}
console.log(greet.language); //english