Skip to main content
change heading word from "EDIT" to "UPDATE"
Source Link

EDITUPDATE: THE SOURCE OF MY UNCERTAINTY

EDIT: THE SOURCE OF MY UNCERTAINTY

UPDATE: THE SOURCE OF MY UNCERTAINTY

describe why I was initially puzzled, leading to this question
Source Link

EDIT: THE SOURCE OF MY UNCERTAINTY

I have discovered why I was puzzled. It turns out that the Stack Overflow code snippet tool produces an ambiguous output when using console.log in this case which lead me to think something was undefined when in fact it was non-existent.

For the simple command console.log([undefined,,4]), the consoles in Chrome, Firefox, Safari and Opera produce correct and unambiguous output:

Chrome:

enter image description here

Firefox:

enter image description here

Safari:

enter image description here

Opera:

enter image description here

However, the output from the code snippet tool on Stack Overflow (in any browser) is ambiguous and at least misleading if not technically incorrect (depending on how you define what console.log should do). (While I eventually posted this question on Software Engineering, which does not have the code snippet tool, I originally worked through the problem on Stack Overflow, which does, leading to me seeing the confusing output shown below.) I have to split the input and output into two separate images just because they are on different parts of the screen...

Stack Overflow code snippet tool input:

enter image description here

Stack Overflow code snippet tool output:

enter image description here

Note that in this output the first and second elements are shown identically, i.e. as undefined, in contrast with all the browser console outputs above which show the first element as undefined but the element in the second position as non-existent.

Just for people's interest, note the following bug in Internet Explorer 11 when I try to show the same thing in its console:

enter image description here

EDIT: THE SOURCE OF MY UNCERTAINTY

I have discovered why I was puzzled. It turns out that the Stack Overflow code snippet tool produces an ambiguous output when using console.log in this case which lead me to think something was undefined when in fact it was non-existent.

For the simple command console.log([undefined,,4]), the consoles in Chrome, Firefox, Safari and Opera produce correct and unambiguous output:

Chrome:

enter image description here

Firefox:

enter image description here

Safari:

enter image description here

Opera:

enter image description here

However, the output from the code snippet tool on Stack Overflow (in any browser) is ambiguous and at least misleading if not technically incorrect (depending on how you define what console.log should do). (While I eventually posted this question on Software Engineering, which does not have the code snippet tool, I originally worked through the problem on Stack Overflow, which does, leading to me seeing the confusing output shown below.) I have to split the input and output into two separate images just because they are on different parts of the screen...

Stack Overflow code snippet tool input:

enter image description here

Stack Overflow code snippet tool output:

enter image description here

Note that in this output the first and second elements are shown identically, i.e. as undefined, in contrast with all the browser console outputs above which show the first element as undefined but the element in the second position as non-existent.

Just for people's interest, note the following bug in Internet Explorer 11 when I try to show the same thing in its console:

enter image description here

removed noise
Source Link
RubberDuck
  • 9k
  • 5
  • 37
  • 44

If someone has enough reputation points to do so, it would be great if this question could be given a new tag: 'undefined'.

Why does the 1st map method below treat element #2 as undefined but the 2nd map method does not?

If someone has enough reputation points to do so, it would be great if this question could be given a new tag: 'undefined'.

Why does the 1st map method below treat element #2 as undefined but the 2nd map method does not?

Why does the 1st map method below treat element #2 as undefined but the 2nd map method does not?

Tweeted twitter.com/StackSoftEng/status/828113145419927552
Source Link
Loading