0

This might be a sillly question, but why the console.log(foo) treats foo as ID and not as variable?

The following code works, but I think it actually should not:

<div id="foo"></div>

<script>
  'use strict';
  console.log(foo);
</script>

And here is how it really should be (in my opinion):

<div id="foo"></div>

<script>
  'use strict';
  const foo = document.querySelector('#foo');
  console.log(foo);
</script>
user90726
  • 837
  • 1
  • 6
  • 25
  • 1
    [No, you shouldn't use this legacy feature](https://stackoverflow.com/q/25325221/1048572) – Bergi Aug 17 '21 at 00:01

0 Answers0