More on other functions, IIFE, Constructor Function, etc.
Anonymous Function:
Anonymous function is nameless function. It cannot be defined independently, as we cannot invoke nameless function. Either can be used with function expression or as a call back function.
IIFE - Immediately Invoked Function Expression
Arguments Object
JavaScript provides an option for receiving arguments using default keyword arguments. We can pass required argument by directly accessing this keyword as below.
Contructor functions:
Constructors in JavaScript are created directly for the functions unlike class objects in other programming languages.
Here , this represent global object in node and windows object in browser.
Remember when JavaScript source is loaded GEC is the first program which gets loaded, it has lexical environment( variable members and reference) , this and metadata. So, this represent global object which is created while JavaScript is loaded.
clearImmediate: [Function: clearImmediate],
setImmediate: [Function: setImmediate] {
[Symbol(nodejs.util.promisify.custom)]: [Getter]
},
clearInterval: [Function: clearInterval],
clearTimeout: [Function: clearTimeout],
setInterval: [Function: setInterval],
setTimeout: [Function: setTimeout] {
[Symbol(nodejs.util.promisify.custom)]: [Getter]
},
queueMicrotask: [Function: queueMicrotask],
structuredClone: [Function: structuredClone],
atob: [Function: atob],
btoa: [Function: btoa],
performance: [Getter/Setter],
fetch: [Function: fetch],
crypto: [Getter],
navigator: [Getter]
}
This is global or window object, all the functions are part of same global/window object. Thus, even we are calling function and executing it, it is getting called via global.function(). Hence, JavaScript is Object Oriented.
Now, if we want we can create a independent constructor function using new keyword as per below.
Person { name: 'Hari', age: 30 }
PS C:\Users\hsapkota\OneDrive - Capgemini\Documents\Ineuron\JS>
Generator function
# this returns
{ value: 1, done: false }
await and sync - to be read further **
Comments
Post a Comment