In this quiz, you will need to find out the output of the value variable. which is declared using let keyword and IIFE return value assigned to it after delete operator.
First, we declare a variable value and assign IIFE (Immediately Invoked Function Expression) function which at the same moment as it declare.
Here, we are passing parameter to IIFE function which is “jsstartup.com“.
And inside the IIFE function, we use the delete keyword and used it on name variable which currently has a “jsstartup.com”.
Return value from IIFE function is going to be assign to value variable.
From now, interesting part begin what really IIFE function return?
Does delete operator really work on the primitives?
Now, why the answer is still “jsstartup.com“. Doesn’t delete remove the value. It should be undefined or null.
Let’s first go through this two point –
IIFE (Immediately Invoked Function Expression) –
A function can be a named one or anonymous function (does not have a name) which can be called whenever you want. But, the IIFE function is a special one because it’s going to be executed as it declared or mounted.
delete operator –
delete work on object and array too. But in array case, index still there but value set to undefined.
So, I hope you understand now. Why we are getting an answer “jsstartup.com“.
But, in our challenge name variable is just a primitive type. So, the delete doesn’t have any impact on the “jsstartup.com” value.
And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page
If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.