Questions about testing for pop up blocker in JS

Questions about testing for pop up blocker in JS


I came across this example in a book that teaches JS. In the lesson he says:

In Internet Explorer, if the popup is blocked, the handle will be undefined instead of null. So to cover all bases, you need to code the function this way.

1 function checkForPopBlocker() {
2 var testPop ="", "","width=100,height=100");
3 if (testPop === null || typeof(testPop === "undefined") {
4 alert("Please disable your popup blocker.");
5 }
6 testPop.close();
7 }

My questions are:
1- Why has he added typeof in line 3?
2- Why adding the quotations marks "" around undefinied?
Why not just coding: if (testPop === null || testPop === undefined)
3- What is the meaning of handle ( I know he means testPop) so what is the general definition of handle?

I will appreciate in-depth explanations with external links.


1- Because you can’t use any undefined var in your code. Accessing undefined var in JS raise an exception.
2- Using typeof we can get string name of type of the object under consideration. Using code you suggested would result in exception as testPop is not defined. Although, i beleive one can safely do if(!testPop) in this case.
3- Handle here is just used here to mean reference.