IE 11 - console.log displays undefined for object properties

This is a fairly short example. I copy and paste the code below into the file, save it and open it. Works great in Chrome, doesn't work, i.e. eleven.

Exit to the console - stupid! What's happening? Stumbled upon some strange mistake?

test.b is clearly not undefined, as it is accessible by the JSON parser and direct object evaluation.

In addition, switching the order of variables in the log function does not change anything so that test.b is undefined.

<!DOCTYPE html> <html> <head> <title>wtf</title> <script> var test = {a:1,b:{c:1}} console.log(test,JSON.stringify(test),test.b); </script> </head> <body> WTF IE </body> </html> 

nonsense

+6
source share
3 answers

You must write your own recursive log function, because the browser only logs in at the first level. To register all by default it will cost too much performance and memory for the browser. See: recursive log function

0
source

I recently ran into this problem.

The problem was that the page I was working on was the compatibility mode set in IE8.

 <meta http-equiv="X-UA-Compatible" content="IE=8" > 

I believe IE8 does not have a console, so console.log will be undefined.

0
source

Source: https://habr.com/ru/post/974460/


All Articles