some questions about the typeof operator of IE9

2019-08-02 08:15发布

问题:

I have been learning the Definitive Guide of JavaScript.i got a question about the typeof opertor. I run the script "alert(typeof window.alert)" in IE9 it proved to be return "function". but if i remove the "DOCTYPE" definition at the top of the html,the result turn to be "object".

I want to know why "DOCTYPE" definition exists or not make a different result. can anyone help me ? 3Q!

回答1:

IE<=8 used to have peculiar object bindings, and the typeof operator returned object where it should have returned function.

Removing the doctype puts IE into quirks mode. This makes sure that older websites can be viewed and older scripts don't throw errors.



回答2:

I found this to be a good explanation:

http://www.w3.org/QA/Tips/Doctype